Made related posts optional
This commit is contained in:
parent
8c1660d84a
commit
e8407e204c
5 changed files with 41 additions and 11 deletions
|
@ -84,14 +84,14 @@ class PostAdmin(PlaceholderAdminMixin, FrontendEditableAdminMixin,
|
|||
'enable_comments',
|
||||
'disable_comments',
|
||||
]
|
||||
if 'djangocms_blog.liveblog' in settings.INSTALLED_APPS:
|
||||
if apps.is_installed('djangocms_blog.liveblog'):
|
||||
actions += ['enable_liveblog', 'disable_liveblog']
|
||||
_fieldsets = [
|
||||
(None, {
|
||||
'fields': [['title', 'categories', 'publish', 'app_config']]
|
||||
}),
|
||||
(None, {
|
||||
'fields': [['related', ]]
|
||||
'fields': [[]]
|
||||
}),
|
||||
(_('Info'), {
|
||||
'fields': [['slug', 'tags'],
|
||||
|
@ -314,14 +314,16 @@ class PostAdmin(PlaceholderAdminMixin, FrontendEditableAdminMixin,
|
|||
|
||||
fsets = deepcopy(self._fieldsets)
|
||||
if config:
|
||||
if config.use_abstract:
|
||||
fsets[0][1]['fields'].append('abstract')
|
||||
if not config.use_placeholder:
|
||||
fsets[0][1]['fields'].append('post_text')
|
||||
abstract = bool(config.use_abstract)
|
||||
placeholder = bool(config.use_placeholder)
|
||||
related = bool(config.use_related)
|
||||
else:
|
||||
if get_setting('USE_ABSTRACT'):
|
||||
abstract = get_setting('USE_ABSTRACT')
|
||||
placeholder = get_setting('USE_PLACEHOLDER')
|
||||
related = get_setting('USE_RELATED')
|
||||
if abstract:
|
||||
fsets[0][1]['fields'].append('abstract')
|
||||
if not get_setting('USE_PLACEHOLDER'):
|
||||
if not placeholder:
|
||||
fsets[0][1]['fields'].append('post_text')
|
||||
if get_setting('MULTISITE') and not self.has_restricted_sites(request):
|
||||
fsets[1][1]['fields'][0].append('sites')
|
||||
|
@ -330,6 +332,8 @@ class PostAdmin(PlaceholderAdminMixin, FrontendEditableAdminMixin,
|
|||
if apps.is_installed('djangocms_blog.liveblog'):
|
||||
fsets[2][1]['fields'][2].append('enable_liveblog')
|
||||
filter_function = get_setting('ADMIN_POST_FIELDSET_FILTER')
|
||||
if related:
|
||||
fsets[1][1]['fields'][0].append('related')
|
||||
if callable(filter_function):
|
||||
fsets = filter_function(fsets, request, obj=obj)
|
||||
return fsets
|
||||
|
@ -388,7 +392,7 @@ class BlogConfigAdmin(BaseAppHookConfig, TranslatableAdmin):
|
|||
(_('Generic'), {
|
||||
'fields': (
|
||||
'config.default_published', 'config.use_placeholder', 'config.use_abstract',
|
||||
'config.set_author',
|
||||
'config.set_author', 'config.use_related',
|
||||
)
|
||||
}),
|
||||
(_('Layout'), {
|
||||
|
|
|
@ -68,6 +68,10 @@ class BlogConfigForm(AppDataForm):
|
|||
label=_('Use abstract field'), required=False,
|
||||
initial=get_setting('USE_ABSTRACT')
|
||||
)
|
||||
use_related = forms.BooleanField(
|
||||
label=_('Enable related posts'), required=False,
|
||||
initial=get_setting('USE_RELATED')
|
||||
)
|
||||
set_author = forms.BooleanField(
|
||||
label=_('Set author'), required=False, help_text=_('Set author by default'),
|
||||
initial=get_setting('AUTHOR_DEFAULT')
|
||||
|
|
|
@ -85,6 +85,7 @@ def get_setting(name):
|
|||
'BLOG_ENABLE_COMMENTS': getattr(settings, 'BLOG_ENABLE_COMMENTS', True),
|
||||
'BLOG_USE_ABSTRACT': getattr(settings, 'BLOG_USE_ABSTRACT', True),
|
||||
'BLOG_USE_PLACEHOLDER': getattr(settings, 'BLOG_USE_PLACEHOLDER', True),
|
||||
'BLOG_USE_RELATED': getattr(settings, 'BLOG_USE_RELATED', True),
|
||||
'BLOG_MULTISITE': getattr(settings, 'BLOG_MULTISITE', True),
|
||||
'BLOG_AUTHOR_DEFAULT': getattr(settings, 'BLOG_AUTHOR_DEFAULT', True),
|
||||
'BLOG_DEFAULT_PUBLISHED': getattr(settings, 'BLOG_DEFAULT_PUBLISHED', False),
|
||||
|
|
|
@ -46,6 +46,8 @@ Global Settings
|
|||
no abstract field is available for every post; (default: ``True``)
|
||||
* BLOG_USE_PLACEHOLDER: Post content is managed via placeholder;
|
||||
if ``False`` a simple HTMLField is used; (default: ``True``)
|
||||
* BLOG_USE_RELATED: Enable related posts to link one post to others;
|
||||
(default: ``True``)
|
||||
* BLOG_MULTISITE: Add support for multisite setup; (default: ``True``)
|
||||
* BLOG_AUTHOR_DEFAULT: Use a default if not specified; if set to ``True`` the
|
||||
current user is set as the default author, if set to ``False`` no default
|
||||
|
@ -121,6 +123,7 @@ be used as defaults.
|
|||
* Use placeholder and plugins for article body: Per-Apphook setting for
|
||||
BLOG_USE_PLACEHOLDER;
|
||||
* Use abstract field: Per-Apphook setting for BLOG_USE_ABSTRACT;
|
||||
* Enable related posts: Per-Apphook setting for BLOG_USE_RELATED;
|
||||
* Set author: Per-Apphook setting for BLOG_AUTHOR_DEFAULT;
|
||||
* Paginate sizePer-Apphook setting for BLOG_PAGINATION;
|
||||
* Template prefix: Alternative directory to load the blog templates from;
|
||||
|
|
|
@ -283,6 +283,24 @@ class AdminTest(BaseTest):
|
|||
|
||||
self.app_config_1.app_data.config.use_placeholder = True
|
||||
self.app_config_1.save()
|
||||
fsets = post_admin.get_fieldsets(request)
|
||||
self.assertFalse('post_text' in fsets[0][1]['fields'])
|
||||
|
||||
# Use related posts
|
||||
self.app_config_1.app_data.config.use_related = True
|
||||
self.app_config_1.save()
|
||||
fsets = post_admin.get_fieldsets(request)
|
||||
self.assertTrue('related' in fsets[1][1]['fields'][0])
|
||||
|
||||
self.app_config_1.app_data.config.use_related = False
|
||||
self.app_config_1.save()
|
||||
fsets = post_admin.get_fieldsets(request)
|
||||
self.assertFalse('related' in fsets[1][1]['fields'][0])
|
||||
|
||||
self.app_config_1.app_data.config.use_related = True
|
||||
self.app_config_1.save()
|
||||
fsets = post_admin.get_fieldsets(request)
|
||||
self.assertTrue('related' in fsets[1][1]['fields'][0])
|
||||
|
||||
# Use abstract
|
||||
self.app_config_1.app_data.config.use_abstract = True
|
||||
|
|
Loading…
Reference in a new issue