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',
|
'enable_comments',
|
||||||
'disable_comments',
|
'disable_comments',
|
||||||
]
|
]
|
||||||
if 'djangocms_blog.liveblog' in settings.INSTALLED_APPS:
|
if apps.is_installed('djangocms_blog.liveblog'):
|
||||||
actions += ['enable_liveblog', 'disable_liveblog']
|
actions += ['enable_liveblog', 'disable_liveblog']
|
||||||
_fieldsets = [
|
_fieldsets = [
|
||||||
(None, {
|
(None, {
|
||||||
'fields': [['title', 'categories', 'publish', 'app_config']]
|
'fields': [['title', 'categories', 'publish', 'app_config']]
|
||||||
}),
|
}),
|
||||||
(None, {
|
(None, {
|
||||||
'fields': [['related', ]]
|
'fields': [[]]
|
||||||
}),
|
}),
|
||||||
(_('Info'), {
|
(_('Info'), {
|
||||||
'fields': [['slug', 'tags'],
|
'fields': [['slug', 'tags'],
|
||||||
|
@ -314,15 +314,17 @@ class PostAdmin(PlaceholderAdminMixin, FrontendEditableAdminMixin,
|
||||||
|
|
||||||
fsets = deepcopy(self._fieldsets)
|
fsets = deepcopy(self._fieldsets)
|
||||||
if config:
|
if config:
|
||||||
if config.use_abstract:
|
abstract = bool(config.use_abstract)
|
||||||
fsets[0][1]['fields'].append('abstract')
|
placeholder = bool(config.use_placeholder)
|
||||||
if not config.use_placeholder:
|
related = bool(config.use_related)
|
||||||
fsets[0][1]['fields'].append('post_text')
|
|
||||||
else:
|
else:
|
||||||
if get_setting('USE_ABSTRACT'):
|
abstract = get_setting('USE_ABSTRACT')
|
||||||
fsets[0][1]['fields'].append('abstract')
|
placeholder = get_setting('USE_PLACEHOLDER')
|
||||||
if not get_setting('USE_PLACEHOLDER'):
|
related = get_setting('USE_RELATED')
|
||||||
fsets[0][1]['fields'].append('post_text')
|
if abstract:
|
||||||
|
fsets[0][1]['fields'].append('abstract')
|
||||||
|
if not placeholder:
|
||||||
|
fsets[0][1]['fields'].append('post_text')
|
||||||
if get_setting('MULTISITE') and not self.has_restricted_sites(request):
|
if get_setting('MULTISITE') and not self.has_restricted_sites(request):
|
||||||
fsets[1][1]['fields'][0].append('sites')
|
fsets[1][1]['fields'][0].append('sites')
|
||||||
if request.user.is_superuser:
|
if request.user.is_superuser:
|
||||||
|
@ -330,6 +332,8 @@ class PostAdmin(PlaceholderAdminMixin, FrontendEditableAdminMixin,
|
||||||
if apps.is_installed('djangocms_blog.liveblog'):
|
if apps.is_installed('djangocms_blog.liveblog'):
|
||||||
fsets[2][1]['fields'][2].append('enable_liveblog')
|
fsets[2][1]['fields'][2].append('enable_liveblog')
|
||||||
filter_function = get_setting('ADMIN_POST_FIELDSET_FILTER')
|
filter_function = get_setting('ADMIN_POST_FIELDSET_FILTER')
|
||||||
|
if related:
|
||||||
|
fsets[1][1]['fields'][0].append('related')
|
||||||
if callable(filter_function):
|
if callable(filter_function):
|
||||||
fsets = filter_function(fsets, request, obj=obj)
|
fsets = filter_function(fsets, request, obj=obj)
|
||||||
return fsets
|
return fsets
|
||||||
|
@ -388,7 +392,7 @@ class BlogConfigAdmin(BaseAppHookConfig, TranslatableAdmin):
|
||||||
(_('Generic'), {
|
(_('Generic'), {
|
||||||
'fields': (
|
'fields': (
|
||||||
'config.default_published', 'config.use_placeholder', 'config.use_abstract',
|
'config.default_published', 'config.use_placeholder', 'config.use_abstract',
|
||||||
'config.set_author',
|
'config.set_author', 'config.use_related',
|
||||||
)
|
)
|
||||||
}),
|
}),
|
||||||
(_('Layout'), {
|
(_('Layout'), {
|
||||||
|
|
|
@ -68,6 +68,10 @@ class BlogConfigForm(AppDataForm):
|
||||||
label=_('Use abstract field'), required=False,
|
label=_('Use abstract field'), required=False,
|
||||||
initial=get_setting('USE_ABSTRACT')
|
initial=get_setting('USE_ABSTRACT')
|
||||||
)
|
)
|
||||||
|
use_related = forms.BooleanField(
|
||||||
|
label=_('Enable related posts'), required=False,
|
||||||
|
initial=get_setting('USE_RELATED')
|
||||||
|
)
|
||||||
set_author = forms.BooleanField(
|
set_author = forms.BooleanField(
|
||||||
label=_('Set author'), required=False, help_text=_('Set author by default'),
|
label=_('Set author'), required=False, help_text=_('Set author by default'),
|
||||||
initial=get_setting('AUTHOR_DEFAULT')
|
initial=get_setting('AUTHOR_DEFAULT')
|
||||||
|
|
|
@ -85,6 +85,7 @@ def get_setting(name):
|
||||||
'BLOG_ENABLE_COMMENTS': getattr(settings, 'BLOG_ENABLE_COMMENTS', True),
|
'BLOG_ENABLE_COMMENTS': getattr(settings, 'BLOG_ENABLE_COMMENTS', True),
|
||||||
'BLOG_USE_ABSTRACT': getattr(settings, 'BLOG_USE_ABSTRACT', True),
|
'BLOG_USE_ABSTRACT': getattr(settings, 'BLOG_USE_ABSTRACT', True),
|
||||||
'BLOG_USE_PLACEHOLDER': getattr(settings, 'BLOG_USE_PLACEHOLDER', 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_MULTISITE': getattr(settings, 'BLOG_MULTISITE', True),
|
||||||
'BLOG_AUTHOR_DEFAULT': getattr(settings, 'BLOG_AUTHOR_DEFAULT', True),
|
'BLOG_AUTHOR_DEFAULT': getattr(settings, 'BLOG_AUTHOR_DEFAULT', True),
|
||||||
'BLOG_DEFAULT_PUBLISHED': getattr(settings, 'BLOG_DEFAULT_PUBLISHED', False),
|
'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``)
|
no abstract field is available for every post; (default: ``True``)
|
||||||
* BLOG_USE_PLACEHOLDER: Post content is managed via placeholder;
|
* BLOG_USE_PLACEHOLDER: Post content is managed via placeholder;
|
||||||
if ``False`` a simple HTMLField is used; (default: ``True``)
|
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_MULTISITE: Add support for multisite setup; (default: ``True``)
|
||||||
* BLOG_AUTHOR_DEFAULT: Use a default if not specified; if set to ``True`` the
|
* 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
|
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
|
* Use placeholder and plugins for article body: Per-Apphook setting for
|
||||||
BLOG_USE_PLACEHOLDER;
|
BLOG_USE_PLACEHOLDER;
|
||||||
* Use abstract field: Per-Apphook setting for BLOG_USE_ABSTRACT;
|
* 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;
|
* Set author: Per-Apphook setting for BLOG_AUTHOR_DEFAULT;
|
||||||
* Paginate sizePer-Apphook setting for BLOG_PAGINATION;
|
* Paginate sizePer-Apphook setting for BLOG_PAGINATION;
|
||||||
* Template prefix: Alternative directory to load the blog templates from;
|
* 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.app_data.config.use_placeholder = True
|
||||||
self.app_config_1.save()
|
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
|
# Use abstract
|
||||||
self.app_config_1.app_data.config.use_abstract = True
|
self.app_config_1.app_data.config.use_abstract = True
|
||||||
|
|
Loading…
Reference in a new issue