Replace @staticmethod by method-based admin actions.

This commit is contained in:
Fabian Braun 2017-03-27 09:49:57 +02:00
parent bce9d56afe
commit 92780aa4b0

View file

@ -86,6 +86,14 @@ class PostAdmin(PlaceholderAdminMixin, FrontendEditableAdminMixin,
raw_id_fields = ['author'] raw_id_fields = ['author']
frontend_editable_fields = ('title', 'abstract', 'post_text') frontend_editable_fields = ('title', 'abstract', 'post_text')
enhance_exclude = ('main_image', 'tags') enhance_exclude = ('main_image', 'tags')
actions = [
'make_published',
'make_unpublished',
'enable_comments',
'disable_comments',
]
if 'djangocms_blog.liveblog' in settings.INSTALLED_APPS:
actions += ['enable_liveblog', 'disable_liveblog']
_fieldsets = [ _fieldsets = [
(None, { (None, {
'fields': [['title', 'categories', 'publish', 'app_config']] 'fields': [['title', 'categories', 'publish', 'app_config']]
@ -112,8 +120,7 @@ class PostAdmin(PlaceholderAdminMixin, FrontendEditableAdminMixin,
_sites = None _sites = None
# Bulk actions for post admin # Bulk actions for post admin
@staticmethod def make_published(self, request, queryset):
def make_published(modeladmin, request, queryset):
""" Bulk action to mark selected posts as published. If """ Bulk action to mark selected posts as published. If
the date_published field is empty the current time is the date_published field is empty the current time is
saved as date_published. saved as date_published.
@ -133,8 +140,7 @@ class PostAdmin(PlaceholderAdminMixin, FrontendEditableAdminMixin,
'%(updates)d entries published.', cnt1+cnt2) % { '%(updates)d entries published.', cnt1+cnt2) % {
'updates': cnt1+cnt2, }) 'updates': cnt1+cnt2, })
@staticmethod def make_unpublished(self, request, queryset):
def make_unpublished(modeladmin, request, queryset):
""" Bulk action to mark selected posts as UNpublished. """ Bulk action to mark selected posts as UNpublished.
queryset must not be empty (ensured by DjangoCMS). queryset must not be empty (ensured by DjangoCMS).
""" """
@ -146,8 +152,7 @@ class PostAdmin(PlaceholderAdminMixin, FrontendEditableAdminMixin,
'%(updates)d entries unpublished.', updates) % { '%(updates)d entries unpublished.', updates) % {
'updates': updates, }) 'updates': updates, })
@staticmethod def enable_comments(self, request, queryset):
def enable_comments(modeladmin, request, queryset):
""" Bulk action to enable comments for selected posts. """ Bulk action to enable comments for selected posts.
queryset must not be empty (ensured by DjangoCMS). queryset must not be empty (ensured by DjangoCMS).
""" """
@ -159,8 +164,7 @@ class PostAdmin(PlaceholderAdminMixin, FrontendEditableAdminMixin,
'Comments for %(updates)d entries enabled', updates) % { 'Comments for %(updates)d entries enabled', updates) % {
'updates': updates, }) 'updates': updates, })
@staticmethod def disable_comments(self, request, queryset):
def disable_comments(modeladmin, request, queryset):
""" Bulk action to disable comments for selected posts. """ Bulk action to disable comments for selected posts.
queryset must not be empty (ensured by DjangoCMS). queryset must not be empty (ensured by DjangoCMS).
""" """
@ -172,8 +176,7 @@ class PostAdmin(PlaceholderAdminMixin, FrontendEditableAdminMixin,
'Comments for %(updates)d entries disabled.', updates) % { 'Comments for %(updates)d entries disabled.', updates) % {
'updates': updates, }) 'updates': updates, })
@staticmethod def enable_liveblog(self, request, queryset):
def enable_liveblog(modeladmin, request, queryset):
""" Bulk action to enable comments for selected posts. """ Bulk action to enable comments for selected posts.
queryset must not be empty (ensured by DjangoCMS). queryset must not be empty (ensured by DjangoCMS).
""" """
@ -185,8 +188,7 @@ class PostAdmin(PlaceholderAdminMixin, FrontendEditableAdminMixin,
'Liveblog for %(updates)d entries enabled.', updates) % { 'Liveblog for %(updates)d entries enabled.', updates) % {
'updates': updates, }) 'updates': updates, })
@staticmethod def disable_liveblog(self, request, queryset):
def disable_liveblog(modeladmin, request, queryset):
""" Bulk action to disable comments for selected posts. """ Bulk action to disable comments for selected posts.
queryset must not be empty (ensured by DjangoCMS). queryset must not be empty (ensured by DjangoCMS).
""" """
@ -199,21 +201,12 @@ class PostAdmin(PlaceholderAdminMixin, FrontendEditableAdminMixin,
'updates': updates, }) 'updates': updates, })
# Make bulk action menu entries localizable # Make bulk action menu entries localizable
make_published.__func__.short_description = _("Publish selection") make_published.short_description = _("Publish selection")
make_unpublished.__func__.short_description = _("Unpublish selection") make_unpublished.short_description = _("Unpublish selection")
enable_comments.__func__.short_description = _("Enable comments for selection") enable_comments.short_description = _("Enable comments for selection")
disable_comments.__func__.short_description = _("Disable comments for selection ") disable_comments.short_description = _("Disable comments for selection ")
enable_liveblog.__func__.short_description = _("Enable liveblog for selection") enable_liveblog.short_description = _("Enable liveblog for selection")
disable_liveblog.__func__.short_description = _("Disable liveblog for selection ") disable_liveblog.short_description = _("Disable liveblog for selection ")
actions = [
make_published.__func__,
make_unpublished.__func__,
enable_comments.__func__,
disable_comments.__func__,
]
if 'djangocms_blog.liveblog' in settings.INSTALLED_APPS:
actions += [enable_liveblog.__func__, disable_liveblog.__func__]
def get_list_filter(self, request): def get_list_filter(self, request):
filters = ['app_config', 'publish', 'date_published'] filters = ['app_config', 'publish', 'date_published']