From 06b58a6a3afbe3e9ffac45b363cfeafcf0e4b3f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yaroslav=20de=20la=20Pe=C3=B1a=20Smirnov?= Date: Wed, 20 Jun 2018 16:14:20 +0300 Subject: rss bug fixes --- setup.py | 2 +- weblog/feeds.py | 22 +++++++++++----------- weblog/urls.py | 17 ++++++++++------- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/setup.py b/setup.py index e9136d0..e9c1b16 100755 --- a/setup.py +++ b/setup.py @@ -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.4', + version='0.3-rss.7', packages=find_packages(), include_package_data=True, license='BSD License', diff --git a/weblog/feeds.py b/weblog/feeds.py index 7e567c2..158e90f 100644 --- a/weblog/feeds.py +++ b/weblog/feeds.py @@ -1,4 +1,4 @@ -from django.contrib.syndication.views. import Feed +from django.contrib.syndication.views import Feed from django.urls import reverse from weblog.models import BlogPost, Translation, Category, CategoryTranslation from weblog.apps import SETTINGS as blog_settings @@ -8,15 +8,15 @@ from django.utils import translation class BlogFeed(Feed): def get_object(self, request, category_slug=None): + self.current_language = translation.get_language() + if self.current_language is None: + self.current_language = settings.LANGUAGE_CODE if category_slug: if category_slug != 'misc': - self.category = Category.objects.get(slug=obj) + self.category = Category.objects.get(slug=category_slug) self.category_name = self.category.name - self.current_language = translation.get_language() - if self.current_language is None: - self.current_language = settings.LANGUAGE_CODE - if IS_MULTILINGUAL and obj != 'misc': - category_translations = CategoryTranslation.objects.filter(category=category) + if blog_settings['multilingual'] and category_slug != 'misc': + category_translations = CategoryTranslation.objects.filter(category=self.category) if category_translations.count() > 0: for cat_trans in category_translations: if self.current_language[0:2] == cat_trans.language[0:2]: @@ -46,10 +46,10 @@ class BlogFeed(Feed): 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): + def item_title(self, item): translation_exists = False post_translations = Translation.objects.filter(post=item) - if post_translations.count() > 0 and blog_settings['multilingual'] + 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] @@ -68,10 +68,10 @@ class BlogFeed(Feed): return item.author.get_full_name() return None - def item_description(self, item, obj): + def item_description(self, item): translation_exists = False post_translations = Translation.objects.filter(post=item) - if post_translation.count() > 0 and blog_settings['multilingual']: + 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] diff --git a/weblog/urls.py b/weblog/urls.py index 4d6a325..b3e95b1 100755 --- a/weblog/urls.py +++ b/weblog/urls.py @@ -4,7 +4,16 @@ from weblog.feeds import BlogFeed from weblog.apps import SETTINGS as blog_settings app_name = 'weblog' -urlpatterns = [ + +urlpatterns = [] + +if blog_settings['enable_rss']: + urlpatterns += [ + url(r'^rss/$', BlogFeed(), name='RSS'), + url(r'^(?P[-\w]+)/rss/$', BlogFeed(), name='CategoryRSS'), + ] + +urlpatterns += [ url(r'^$', views.Index, name='Index'), url(r'^change-language/(?P[-\w]+)/$', views.ChangeLanguage, name='ChangeLanguage'), url(r'^(?P[0-9]{4})/$', views.Index, name='ArchiveIndex'), @@ -12,9 +21,3 @@ urlpatterns = [ url(r'^(?P[-\w]+)/$', views.Index, name='CategoryIndex'), url(r'^(?P[-\w]+)/(?P[-\w]+)/$', views.PostView, name='PostView'), ] - -if blog_settings['enable_rss']: - urlpatters += [ - url(r'^/rss/$', BlogFeed(), name='RSS'), - url(r'^/(?P[-\w]+)/rss/$', BlogFeed(), name='CategoryRSS'), - ] -- cgit v1.2.3