Added: Test for new default image sizes
This commit is contained in:
parent
23e0e56742
commit
a341275ac8
3 changed files with 33 additions and 11 deletions
|
@ -45,14 +45,14 @@ class BlogConfigForm(AppDataForm):
|
|||
label=_('Default size of full images'),
|
||||
queryset=ThumbnailOption.objects.all(),
|
||||
required=False,
|
||||
help_text=_('If left empty the image size will have to be set for '
|
||||
help_text=_('If left empty the image size will have to be set for '
|
||||
'every newly created post.'),
|
||||
)
|
||||
default_image_thumbnail = forms.ModelChoiceField(
|
||||
label=_('Default size of thumbnail images'),
|
||||
queryset=ThumbnailOption.objects.all(),
|
||||
required=False,
|
||||
help_text=_('If left empty the thumbnail image size will have to be '
|
||||
help_text=_('If left empty the thumbnail image size will have to be '
|
||||
'set for every newly created post.'),
|
||||
)
|
||||
url_patterns = forms.ChoiceField(
|
||||
|
|
|
@ -56,6 +56,7 @@ class PostAdminForm(TranslatableModelForm):
|
|||
|
||||
qs = BlogCategory.objects
|
||||
|
||||
config = None
|
||||
if getattr(self.instance, 'app_config_id', None):
|
||||
qs = qs.namespace(self.instance.app_config.namespace)
|
||||
elif 'initial' in kwargs and 'app_config' in kwargs['initial']:
|
||||
|
@ -70,12 +71,9 @@ class PostAdminForm(TranslatableModelForm):
|
|||
# apphook-config is to create an apphook on a cms Page.
|
||||
self.fields['app_config'].widget.can_add_related = False
|
||||
|
||||
if 'app_config' in self.data and self.data['app_config'] \
|
||||
and not self.instance.id: # Instance must not be saved (yet)
|
||||
config = BlogConfig.objects.get(pk=int(self.data['app_config']))
|
||||
if 'main_image_full' not in self.data or self.data['main_image_full'] == '':
|
||||
default = config.app_data['config'].get('default_image_full')
|
||||
self.data['main_image_full'] = str(default.id) if default else ''
|
||||
if 'main_image_thumbnail' not in self.data or self.data['main_image_thumbnail'] == '':
|
||||
default = config.app_data['config'].get('default_image_thumbnail')
|
||||
self.data['main_image_thumbnail'] = str(default.id) if default else ''
|
||||
if config:
|
||||
self.initial['main_image_full'] = \
|
||||
config.app_data['config'].get('default_image_full')
|
||||
self.initial['main_image_thumbnail'] = \
|
||||
config.app_data['config'].get('default_image_thumbnail')
|
||||
|
||||
|
|
|
@ -30,6 +30,12 @@ from djangocms_blog.settings import MENU_TYPE_NONE, get_setting
|
|||
|
||||
from .base import BaseTest
|
||||
|
||||
try: # pragma: no cover
|
||||
from cmsplugin_filer_image.models import ThumbnailOption # NOQA
|
||||
except ImportError: # pragma: no cover
|
||||
from filer.models import ThumbnailOption # NOQA
|
||||
|
||||
|
||||
try:
|
||||
from unittest import SkipTest
|
||||
except ImportError:
|
||||
|
@ -48,6 +54,20 @@ class AdminTest(BaseTest):
|
|||
def setUp(self):
|
||||
super(AdminTest, self).setUp()
|
||||
admin.autodiscover()
|
||||
self.default_thumbnail = ThumbnailOption.objects.create(
|
||||
name='Blog thumbnail',
|
||||
width=120,
|
||||
height=120,
|
||||
crop=True,
|
||||
upscale=True,
|
||||
)
|
||||
self.default_full = ThumbnailOption.objects.create(
|
||||
name='Blog image',
|
||||
width=800,
|
||||
height=200,
|
||||
crop=True,
|
||||
upscale=True,
|
||||
)
|
||||
|
||||
def test_admin_post_views(self):
|
||||
self.get_pages()
|
||||
|
@ -237,6 +257,8 @@ class AdminTest(BaseTest):
|
|||
self.assertFalse('abstract' in fsets[0][1]['fields'])
|
||||
|
||||
self.app_config_1.app_data.config.use_abstract = True
|
||||
self.app_config_1.app_data.config.default_image_full = self.default_full
|
||||
self.app_config_1.app_data.config.default_image_thumbnail = self.default_thumbnail
|
||||
self.app_config_1.save()
|
||||
|
||||
with self.settings(BLOG_MULTISITE=True):
|
||||
|
@ -264,6 +286,8 @@ class AdminTest(BaseTest):
|
|||
self.category_1.pk, self.category_1.safe_translation_getter('name', language_code='en')
|
||||
))
|
||||
self.assertContains(response, 'id="id_sites" name="sites"')
|
||||
self.assertContains(response, 'selected="selected">Blog image')
|
||||
self.assertContains(response, 'selected="selected">Blog thumbnail')
|
||||
|
||||
self.user.sites.add(self.site_1)
|
||||
with self.login_user_context(self.user):
|
||||
|
|
Loading…
Reference in a new issue