From ac7d450e655cea6daf9ce92f23bcc50cb6b81e17 Mon Sep 17 00:00:00 2001 From: Iacopo Spalletti Date: Fri, 10 Oct 2014 00:37:24 +0200 Subject: [PATCH] Use the toolbar status to check whether to use published or all the posts --- djangocms_blog/views.py | 2 +- tests/test_views.py | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/djangocms_blog/views.py b/djangocms_blog/views.py index e3ea0b9..251ffe1 100644 --- a/djangocms_blog/views.py +++ b/djangocms_blog/views.py @@ -19,7 +19,7 @@ class BaseBlogView(ViewUrlMixin): def get_queryset(self): language = get_language() queryset = self.model._default_manager.language(language_code=language) - if not self.request.user.is_staff: + if not self.request.toolbar or not self.request.toolbar.edit_mode: queryset = queryset.published() return queryset.on_site() diff --git a/tests/test_views.py b/tests/test_views.py index 69621b0..4f7da17 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -4,6 +4,7 @@ from django.http import Http404 from django.utils.translation import activate from django.utils.timezone import now from parler.utils.context import switch_language +from cms.middleware.toolbar import ToolbarMiddleware from djangocms_blog.models import Post, BlogCategory from djangocms_blog.feeds import LatestEntriesFeed, TagFeed from djangocms_blog.sitemaps import BlogSitemap @@ -28,6 +29,14 @@ class ViewTest(BaseTest): self.assertEqual(list(view_obj.get_queryset()), [post1]) request = self.get_page_request(page1, self.user, r'/en/blog/', edit=False) + activate('en') + view_obj.request = request + view_obj.kwargs = {} + qs = view_obj.get_queryset() + self.assertEqual(qs.count(), 1) + self.assertEqual(set(qs), set([post1])) + + request = self.get_page_request(page1, self.user, r'/en/blog/', edit=True) view_obj.request = request self.assertEqual(set(view_obj.get_queryset()), set([post1, post2])) @@ -42,7 +51,7 @@ class ViewTest(BaseTest): response = view_obj.render_to_response(context) self.assertContains(response, context['post_list'][0].get_absolute_url()) - request = self.get_page_request(page1, self.user, r'/it/blog/', lang_code='it', edit=False) + request = self.get_page_request(page1, self.user, r'/it/blog/', lang_code='it', edit=True) activate('it') view_obj.request = request view_obj.object_list = view_obj.get_queryset() @@ -106,7 +115,7 @@ class ViewTest(BaseTest): page1, page2 = self.get_pages() post1, post2 = self.get_posts() - request = self.get_page_request(page1, self.user, r'/en/blog/', edit=False) + request = self.get_page_request(page1, self.user, r'/en/blog/', edit=True) activate('en') view_obj = CategoryEntriesView() view_obj.request = request @@ -129,7 +138,7 @@ class ViewTest(BaseTest): page1, page2 = self.get_pages() post1, post2 = self.get_posts() - request = self.get_page_request(page1, self.user, r'/en/blog/', edit=False) + request = self.get_page_request(page1, self.user, r'/en/blog/', edit=True) activate('en') view_obj = AuthorEntriesView() view_obj.request = request @@ -156,7 +165,7 @@ class ViewTest(BaseTest): post2.tags.add('tag 6', 'tag 2', 'tag 5', 'tag 8') post2.save() - request = self.get_page_request(page1, self.user, r'/en/blog/', edit=False) + request = self.get_page_request(page1, self.user, r'/en/blog/', edit=True) activate('en') view_obj = TaggedListView() view_obj.request = request