Merge pull request #45 from nephila/feature/fix_live_mode

Use the toolbar status to check whether to filter posts
This commit is contained in:
Iacopo Spalletti 2014-10-10 14:16:38 +02:00
commit 24cfa6f1d1
2 changed files with 14 additions and 5 deletions

View file

@ -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()

View file

@ -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