Merge pull request #412 from nephila/feature/use_related_flag

Made related posts optional
This commit is contained in:
Iacopo Spalletti 2018-01-13 15:57:05 +01:00 committed by GitHub
commit 2e7c181278
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 41 additions and 11 deletions

View file

@ -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,15 +314,17 @@ 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'):
fsets[0][1]['fields'].append('abstract')
if not get_setting('USE_PLACEHOLDER'):
fsets[0][1]['fields'].append('post_text')
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 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')
if request.user.is_superuser:
@ -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'), {

View file

@ -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')

View file

@ -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),

View file

@ -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;

View file

@ -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