From 83a3802b6a367ed20ef2c32552dc9edf0325fb5e Mon Sep 17 00:00:00 2001 From: Fabian Braun Date: Mon, 27 Mar 2017 11:00:30 +0200 Subject: [PATCH] Preset image and thumbnail sizes on a per app level. --- djangocms_blog/admin.py | 1 + djangocms_blog/cms_appconfig.py | 19 +++++++++++++++++++ djangocms_blog/forms.py | 10 ++++++++++ 3 files changed, 30 insertions(+) diff --git a/djangocms_blog/admin.py b/djangocms_blog/admin.py index f7cbb8b..4037db1 100755 --- a/djangocms_blog/admin.py +++ b/djangocms_blog/admin.py @@ -411,6 +411,7 @@ class BlogConfigAdmin(BaseAppHookConfig, TranslatableAdmin): 'fields': ( 'config.paginate_by', 'config.url_patterns', 'config.template_prefix', 'config.menu_structure', 'config.menu_empty_categories', + ('config.default_image_full', 'config.default_image_thumbnail'), ), 'classes': ('collapse',) }), diff --git a/djangocms_blog/cms_appconfig.py b/djangocms_blog/cms_appconfig.py index 36ff2cc..24cbea5 100644 --- a/djangocms_blog/cms_appconfig.py +++ b/djangocms_blog/cms_appconfig.py @@ -11,6 +11,11 @@ from parler.models import TranslatableModel, TranslatedFields from .settings import MENU_TYPE_COMPLETE, get_setting +try: # pragma: no cover + from cmsplugin_filer_image.models import ThumbnailOption # NOQA +except ImportError: # pragma: no cover + from filer.models import ThumbnailOption # NOQA + class BlogConfig(TranslatableModel, AppHookConfig): """ @@ -36,6 +41,20 @@ class BlogConfigForm(AppDataForm): label=_('Post published by default'), required=False, initial=get_setting('DEFAULT_PUBLISHED') ) + default_image_full = forms.ModelChoiceField( + 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 ' + '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 ' + 'set for every newly created post.'), + ) url_patterns = forms.ChoiceField( label=_('Permalink structure'), required=False, initial=get_setting('AVAILABLE_PERMALINK_STYLES')[0][0], diff --git a/djangocms_blog/forms.py b/djangocms_blog/forms.py index 7ccadd7..bd703cd 100644 --- a/djangocms_blog/forms.py +++ b/djangocms_blog/forms.py @@ -69,3 +69,13 @@ class PostAdminForm(TranslatableModelForm): # Don't allow app_configs to be added here. The correct way to add an # 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 ''