From b218ee1662677955759005ec2c95089f0d928414 Mon Sep 17 00:00:00 2001 From: PCoder Date: Tue, 17 Apr 2018 11:47:56 +0200 Subject: [PATCH 1/7] Add urlconfs for comic --- dynamicweb/urls.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/dynamicweb/urls.py b/dynamicweb/urls.py index edb7e3b7..8f9f5b1c 100644 --- a/dynamicweb/urls.py +++ b/dynamicweb/urls.py @@ -11,6 +11,7 @@ from hosting.views import ( RailsHostingView, DjangoHostingView, NodeJSHostingView ) from membership import urls as membership_urls +from ungleich import views as ungleich_views from ungleich_page.views import LandingView from django.views.generic import RedirectView from django.core.urlresolvers import reverse_lazy @@ -60,6 +61,13 @@ urlpatterns += i18n_patterns( url=reverse_lazy('ungleich:post-list') ), name='blog_list_view' ), + url(r'^comic/(?P\d{4})/(?P\d{1,2})/(?P\d{1,2})/(?P\w[-\w]*)/$', + RedirectView.as_view(pattern_name='ungleich:post-detail')), + url(r'^comic/$', + ungleich_views.PostListViewUngleich.as_view( + tags='comic' + ), + name='blog_list_view'), url(r'^cms/', include('cms.urls')), url(r'^$', RedirectView.as_view(url='/cms') if REDIRECT_TO_CMS else LandingView.as_view()), From ee35fbd7849f5d2d1ea49773038024928ba84351 Mon Sep 17 00:00:00 2001 From: PCoder Date: Tue, 17 Apr 2018 11:49:01 +0200 Subject: [PATCH 2/7] Attempt to filter blogs by category --- ungleich/views.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/ungleich/views.py b/ungleich/views.py index 3610d1bc..36583a04 100644 --- a/ungleich/views.py +++ b/ungleich/views.py @@ -7,6 +7,7 @@ from djangocms_blog.models import Post from djangocms_blog.views import PostListView from djangocms_blog.settings import get_setting from django.utils.translation import ugettext_lazy as _ +from djangocms_blog.models import BlogCategory def blog(request): @@ -20,6 +21,7 @@ def blog(request): class PostListViewUngleich(PostListView): + tags = None model = Post context_object_name = 'post_list' base_template_name = 'post_list_ungleich.html' @@ -38,7 +40,17 @@ class PostListViewUngleich(PostListView): def get_queryset(self): language = get_language() - queryset = self.model.objects.filter(publish=True).translated(language) + if self.tags: + queryset = (self.model + .objects + .filter(tags__name__in=[self.tags], publish=True) + .translated(language)) + else: + queryset = (self.model + .objects + .filter(publish=True) + .translated(language) + ) setattr(self.request, get_setting('CURRENT_NAMESPACE'), self.config) return queryset From ff1d4f1a6fb211b7d72366e344d40dd3124b6328 Mon Sep 17 00:00:00 2001 From: "M.Ravi" Date: Tue, 17 Apr 2018 16:15:49 +0200 Subject: [PATCH 3/7] Rename tags to category, because thats how we filter posts by --- dynamicweb/urls.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dynamicweb/urls.py b/dynamicweb/urls.py index 8f9f5b1c..20e9df3b 100644 --- a/dynamicweb/urls.py +++ b/dynamicweb/urls.py @@ -65,7 +65,7 @@ urlpatterns += i18n_patterns( RedirectView.as_view(pattern_name='ungleich:post-detail')), url(r'^comic/$', ungleich_views.PostListViewUngleich.as_view( - tags='comic' + category='comic' ), name='blog_list_view'), url(r'^cms/', include('cms.urls')), From 7d211b33333ebca6e559f2c46f7bd2dc220dc309 Mon Sep 17 00:00:00 2001 From: "M.Ravi" Date: Tue, 17 Apr 2018 16:17:25 +0200 Subject: [PATCH 4/7] Modify PostListViewUngleich: Filter posts by category if specified --- ungleich/views.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/ungleich/views.py b/ungleich/views.py index 36583a04..c1d7445d 100644 --- a/ungleich/views.py +++ b/ungleich/views.py @@ -21,7 +21,7 @@ def blog(request): class PostListViewUngleich(PostListView): - tags = None + category = None model = Post context_object_name = 'post_list' base_template_name = 'post_list_ungleich.html' @@ -40,10 +40,20 @@ class PostListViewUngleich(PostListView): def get_queryset(self): language = get_language() - if self.tags: + if self.category: + blog_category = ( + BlogCategory + ._default_manager + .language(language) + .filter( + translations__language_code=language, + translations__slug=self.category + ) + ) + queryset = (self.model .objects - .filter(tags__name__in=[self.tags], publish=True) + .filter(categories=blog_category, publish=True) .translated(language)) else: queryset = (self.model From 80a568b2b382a763f108d809249f2e71bf69ff0c Mon Sep 17 00:00:00 2001 From: "M.Ravi" Date: Tue, 17 Apr 2018 17:14:39 +0200 Subject: [PATCH 5/7] Remove unwanted /comic/... urlconf --- dynamicweb/urls.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/dynamicweb/urls.py b/dynamicweb/urls.py index 20e9df3b..09aa4fa8 100644 --- a/dynamicweb/urls.py +++ b/dynamicweb/urls.py @@ -61,8 +61,6 @@ urlpatterns += i18n_patterns( url=reverse_lazy('ungleich:post-list') ), name='blog_list_view' ), - url(r'^comic/(?P\d{4})/(?P\d{1,2})/(?P\d{1,2})/(?P\w[-\w]*)/$', - RedirectView.as_view(pattern_name='ungleich:post-detail')), url(r'^comic/$', ungleich_views.PostListViewUngleich.as_view( category='comic' From 8b5b353e59a663cc5d9c3a678b549ca0aa1af2d1 Mon Sep 17 00:00:00 2001 From: "M.Ravi" Date: Tue, 17 Apr 2018 17:15:23 +0200 Subject: [PATCH 6/7] Reformat code and give proper name to comic urlconf --- dynamicweb/urls.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/dynamicweb/urls.py b/dynamicweb/urls.py index 09aa4fa8..50bc10ec 100644 --- a/dynamicweb/urls.py +++ b/dynamicweb/urls.py @@ -62,10 +62,8 @@ urlpatterns += i18n_patterns( ), name='blog_list_view' ), url(r'^comic/$', - ungleich_views.PostListViewUngleich.as_view( - category='comic' - ), - name='blog_list_view'), + ungleich_views.PostListViewUngleich.as_view(category='comic'), + name='comic_post_list_view'), url(r'^cms/', include('cms.urls')), url(r'^$', RedirectView.as_view(url='/cms') if REDIRECT_TO_CMS else LandingView.as_view()), From b3d36c1be3bf9485d8bedb89f0faf20a5ee6ded4 Mon Sep 17 00:00:00 2001 From: "M.Ravi" Date: Tue, 17 Apr 2018 18:12:45 +0200 Subject: [PATCH 7/7] Reformat code --- ungleich/views.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ungleich/views.py b/ungleich/views.py index c1d7445d..af7cb304 100644 --- a/ungleich/views.py +++ b/ungleich/views.py @@ -59,8 +59,7 @@ class PostListViewUngleich(PostListView): queryset = (self.model .objects .filter(publish=True) - .translated(language) - ) + .translated(language)) setattr(self.request, get_setting('CURRENT_NAMESPACE'), self.config) return queryset