diff --git a/djangocms_blog/admin.py b/djangocms_blog/admin.py index df54af0..ad7701e 100755 --- a/djangocms_blog/admin.py +++ b/djangocms_blog/admin.py @@ -7,7 +7,6 @@ from django.conf import settings from parler.admin import TranslatableAdmin from .models import Post, BlogCategory -from .settings import BLOG_USE_PLACEHOLDER, BLOG_MULTISITE class BlogCategoryAdmin(EnhancedModelAdminMixin, TranslatableAdmin): @@ -48,6 +47,7 @@ class PostAdmin(EnhancedModelAdminMixin, FrontendEditableAdmin, ] def get_fieldsets(self, request, obj=None): + from .settings import BLOG_USE_PLACEHOLDER, BLOG_MULTISITE fsets = deepcopy(self._fieldsets) if not BLOG_USE_PLACEHOLDER: fsets[0][1]['fields'].append('post_text') diff --git a/djangocms_blog/managers.py b/djangocms_blog/managers.py index d2420ed..cc728cd 100644 --- a/djangocms_blog/managers.py +++ b/djangocms_blog/managers.py @@ -123,7 +123,7 @@ class GenericDateTaggedManager(TaggedFilterItem, TranslationManager): def get_queryset(self, *args, **kwargs): try: return super(GenericDateTaggedManager, self).get_queryset(*args, **kwargs) - except AttributeError: + except AttributeError: # pragma: no cover return super(GenericDateTaggedManager, self).get_query_set(*args, **kwargs) if django.VERSION < (1, 8): get_query_set = get_queryset diff --git a/tests/__init__.py b/tests/__init__.py index 1c2b152..16b18fc 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -12,7 +12,7 @@ from django.contrib.sites.models import Site from django.core.files import File as DjangoFile from django.http import SimpleCookie from django.test import TestCase, RequestFactory -from django.utils.translation import activate, override +from django.utils.translation import activate from filer.models import File, Image from PIL import Image as PilImage, ImageDraw from six import StringIO @@ -164,16 +164,15 @@ class BaseTest(TestCase): return request def get_posts(self, sites=None): - with override('en'): - post1 = self._get_post(self.data['en'][0], sites=sites) - post1 = self._get_post(self.data['it'][0], post1, 'it') - post1.publish = True - post1.main_image = self.img - post1.save() - post2 = self._get_post(self.data['en'][1], sites=sites) - post2 = self._get_post(self.data['it'][1], post2, 'it') - post2.main_image = self.img - post2.save() + post1 = self._get_post(self.data['en'][0], sites=sites) + post1 = self._get_post(self.data['it'][0], post1, 'it') + post1.publish = True + post1.main_image = self.img + post1.save() + post2 = self._get_post(self.data['en'][1], sites=sites) + post2 = self._get_post(self.data['it'][1], post2, 'it') + post2.main_image = self.img + post2.save() return post1, post2 diff --git a/tests/test_models.py b/tests/test_models.py index 9ee7527..8a6948f 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -2,6 +2,7 @@ from cms.api import add_plugin from cms.utils.copy_plugins import copy_plugins_to from cms.utils.plugins import downcast_plugins +from django.contrib import admin from django.contrib.sites.models import Site from django.core.urlresolvers import reverse from django.utils.timezone import now @@ -16,6 +17,33 @@ from djangocms_blog import settings from . import BaseTest +class AdminTest(BaseTest): + + def test_admin_fieldsets(self): + request = self.get_page_request('/', self.user_staff, r'/en/blog/', edit=False) + post_admin = admin.site._registry[Post] + + settings.BLOG_USE_PLACEHOLDER = True + fsets = post_admin.get_fieldsets(request) + self.assertFalse('post_text' in fsets[0][1]['fields']) + settings.BLOG_USE_PLACEHOLDER = False + fsets = post_admin.get_fieldsets(request) + self.assertTrue('post_text' in fsets[0][1]['fields']) + settings.BLOG_USE_PLACEHOLDER = True + + settings.BLOG_MULTISITE = True + fsets = post_admin.get_fieldsets(request) + self.assertTrue('sites' in fsets[1][1]['fields'][0]) + settings.BLOG_MULTISITE = False + fsets = post_admin.get_fieldsets(request) + self.assertFalse('sites' in fsets[1][1]['fields'][0]) + settings.BLOG_MULTISITE = True + + request = self.get_page_request('/', self.user, r'/en/blog/', edit=False) + fsets = post_admin.get_fieldsets(request) + self.assertTrue('author' in fsets[1][1]['fields'][0]) + + class ModelsTest(BaseTest): def test_model_attributes(self): @@ -219,14 +247,15 @@ class ModelsTest(BaseTest): self.assertEqual(set(new[0].authors.all()), set([self.user])) def test_multisite(self): - post1 = self._get_post(self.data['en'][0], sites=(self.site_1,)) - post2 = self._get_post(self.data['en'][1], sites=(self.site_2,)) - post3 = self._get_post(self.data['en'][2], sites=(self.site_2, self.site_1)) + with override('en'): + post1 = self._get_post(self.data['en'][0], sites=(self.site_1,)) + post2 = self._get_post(self.data['en'][1], sites=(self.site_2,)) + post3 = self._get_post(self.data['en'][2], sites=(self.site_2, self.site_1)) - self.assertEqual(len(Post.objects.all()), 3) - with self.settings(**{'SITE_ID': 1}): - self.assertEqual(len(Post.objects.all().on_site()), 2) - self.assertEqual(set(list(Post.objects.all().on_site())), set([post1, post3])) - with self.settings(**{'SITE_ID': 2}): - self.assertEqual(len(Post.objects.all().on_site()), 2) - self.assertEqual(set(list(Post.objects.all().on_site())), set([post2, post3])) + self.assertEqual(len(Post.objects.all()), 3) + with self.settings(**{'SITE_ID': self.site_1.pk}): + self.assertEqual(len(Post.objects.all().on_site()), 2) + self.assertEqual(set(list(Post.objects.all().on_site())), set([post1, post3])) + with self.settings(**{'SITE_ID': self.site_2.pk}): + self.assertEqual(len(Post.objects.all().on_site()), 2) + self.assertEqual(set(list(Post.objects.all().on_site())), set([post2, post3]))