Preset image and thumbnail sizes on a per app level.
This commit is contained in:
parent
92780aa4b0
commit
83a3802b6a
3 changed files with 30 additions and 0 deletions
|
@ -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',)
|
||||
}),
|
||||
|
|
|
@ -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],
|
||||
|
|
|
@ -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 ''
|
||||
|
|
Loading…
Reference in a new issue