diff options
author | Yaroslav de la Peña Smirnov <contact@yaroslavps.com> | 2018-06-20 15:04:19 +0300 |
---|---|---|
committer | Yaroslav de la Peña Smirnov <contact@yaroslavps.com> | 2018-06-20 15:04:19 +0300 |
commit | 812fbefe190a4a9d4f5250ba39411a50e9167448 (patch) | |
tree | 4495619aabe3d91e6be72032bfcc1a3417a20d8b | |
parent | 13a762341f349e5a9aa17c049cb0803d12f4408d (diff) | |
download | w3blog-812fbefe190a4a9d4f5250ba39411a50e9167448.tar.gz w3blog-812fbefe190a4a9d4f5250ba39411a50e9167448.zip |
rss added in feeds.py
-rwxr-xr-x | setup.py | 2 | ||||
-rw-r--r-- | weblog/feeds.py | 38 |
2 files changed, 35 insertions, 5 deletions
@@ -9,7 +9,7 @@ os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir))) setup( name='django-weblog', - version='0.3-rss.2', + version='0.3-rss.3', packages=find_packages(), include_package_data=True, license='BSD License', diff --git a/weblog/feeds.py b/weblog/feeds.py index 8510813..d7ccb23 100644 --- a/weblog/feeds.py +++ b/weblog/feeds.py @@ -1,6 +1,6 @@ from django.contrib.syndication.views. import Feed from django.urls import reverse -from weblog.models import BlogPost, Category, CategoryTranslation +from weblog.models import BlogPost, Translation, Category, CategoryTranslation from weblog.apps import SETTINGS as blog_settings from django.utils.translation import ugettext_lazy as _, pgettext_lazy from django.utils import translation @@ -56,10 +56,40 @@ class BlogFeed(Feed): return _('Latest blog posts on %(blog_title)s') % {'blog_title': blog_settings['blog_title']} def items(self, obj): - pass + if obj: + return BlogPost.objects.filter(category__slug=obj).order_by('-publish_date')[:blog_settings['posts_per_page']] + return BlogPost.objects.order_by('-publish_date')[:blog_settings['posts_per_page']] def item_title(self, item, obj): - pass + translation_exists = False + post_translations = Translation.objects.filter(post=item) + if post_translations.count() > 0 and blog_settings['multilingual'] + orig_lang = item.original_language + if len(orig_lang) < 2: + orig_lang = settings.LANGUAGE_CODE[0:2] + for post_translation in post_translations: + if self.current_language[0:2] == post_translation.language[0:2]: + return post_translation.title + return item.title + + def item_pubdate(self, item): + return item.publish_date + + def item_author_name(self, item): + if blog_settings['show_author']: + if blog_settings['use_authors_username']: + return item.author.get_username() + return item.author.get_full_name() + return None def item_description(self, item, obj): - pass + translation_exists = False + post_translations = Translation.objects.filter(post=item) + if post_translation.count() > 0 and blog_settings['multilingual']: + orig_lang = item.original_language + if len(orig_lang) < 2: + orig_lang = settings.LANGUAGE_CODE[0:2] + for post_translation in post_translations: + if self.current_language[:2] == post_translation.language[:2]: + return post_translation.content + return item.content |