Add bulk actions for posts: publish, unpublish, allow/disallow comments, and enable/disable liveblog (if installed)
This commit is contained in:
parent
6bf6bdc159
commit
9d21af9297
8 changed files with 75 additions and 0 deletions
|
@ -16,6 +16,7 @@ Contributors
|
|||
* cluster-master
|
||||
* danra
|
||||
* Davide Truffo
|
||||
* Fabian Braun
|
||||
* frnhr
|
||||
* furiousdave
|
||||
* Georgiy Kutsurua
|
||||
|
|
|
@ -9,6 +9,7 @@ from tempfile import mkdtemp
|
|||
|
||||
def gettext(s): return s
|
||||
|
||||
|
||||
HELPER_SETTINGS = dict(
|
||||
ROOT_URLCONF='tests.test_utils.urls',
|
||||
INSTALLED_APPS=[
|
||||
|
@ -139,5 +140,6 @@ def setup():
|
|||
from djangocms_helper import runner
|
||||
runner.setup('djangocms_blog', sys.modules[__name__], use_cms=True)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
run()
|
||||
|
|
|
@ -14,6 +14,7 @@ from django.contrib import admin
|
|||
from django.contrib.sites.models import Site
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.utils import timezone
|
||||
from django.utils.six import callable
|
||||
from django.utils.translation import get_language_from_request, ugettext_lazy as _
|
||||
from parler.admin import TranslatableAdmin
|
||||
|
@ -30,6 +31,59 @@ except ImportError:
|
|||
pass
|
||||
|
||||
|
||||
# Bulk actions for post admin
|
||||
def make_published(modeladmin, request, queryset):
|
||||
""" Bulk action to mark selected posts as published. If
|
||||
the date_published field is empty the current time is
|
||||
saved as date_published.
|
||||
"""
|
||||
for post in queryset:
|
||||
if not post.publish:
|
||||
if not post.date_published:
|
||||
post.date_published = timezone.now()
|
||||
post.publish = True
|
||||
post.save()
|
||||
|
||||
|
||||
def make_unpublished(modeladmin, request, queryset):
|
||||
""" Bulk action to mark selected posts as UNpublished.
|
||||
"""
|
||||
queryset.update(publish=False)
|
||||
|
||||
|
||||
def enable_comments(modeladmin, request, queryset):
|
||||
""" Bulk action to enable comments for selected posts.
|
||||
"""
|
||||
queryset.update(enable_comments=True)
|
||||
|
||||
|
||||
def disable_comments(modeladmin, request, queryset):
|
||||
""" Bulk action to disable comments for selected posts.
|
||||
"""
|
||||
queryset.update(enable_comments=False)
|
||||
|
||||
|
||||
def enable_liveblog(modeladmin, request, queryset):
|
||||
""" Bulk action to enable comments for selected posts.
|
||||
"""
|
||||
queryset.update(enable_liveblog=True)
|
||||
|
||||
|
||||
def disable_liveblog(modeladmin, request, queryset):
|
||||
""" Bulk action to disable comments for selected posts.
|
||||
"""
|
||||
queryset.update(enable_liveblog=False)
|
||||
|
||||
|
||||
# Make bulk action menu entries localizable
|
||||
make_published.short_description = _("Publish selection")
|
||||
make_unpublished.short_description = _("Unpublish selection")
|
||||
enable_comments.short_description = _("Enable comments for selection")
|
||||
disable_comments.short_description = _("Disable comments for selection ")
|
||||
enable_liveblog.short_description = _("Enable liveblog for selection")
|
||||
disable_liveblog.short_description = _("Disable liveblog for selection ")
|
||||
|
||||
|
||||
class BlogCategoryAdmin(EnhancedModelAdminMixin, ModelAppHookConfig, TranslatableAdmin):
|
||||
form = CategoryAdminForm
|
||||
list_display = [
|
||||
|
@ -58,6 +112,14 @@ class PostAdmin(PlaceholderAdminMixin, FrontendEditableAdminMixin,
|
|||
list_filter = ('app_config',)
|
||||
date_hierarchy = 'date_published'
|
||||
raw_id_fields = ['author']
|
||||
actions = [
|
||||
make_published,
|
||||
make_unpublished,
|
||||
enable_comments,
|
||||
disable_comments,
|
||||
]
|
||||
if 'djangocms_blog.liveblog' in settings.INSTALLED_APPS:
|
||||
actions += [enable_liveblog, disable_liveblog]
|
||||
frontend_editable_fields = ('title', 'abstract', 'post_text')
|
||||
enhance_exclude = ('main_image', 'tags')
|
||||
_fieldsets = [
|
||||
|
@ -329,6 +391,7 @@ class BlogConfigAdmin(BaseAppHookConfig, TranslatableAdmin):
|
|||
menu_pool.clear(all=True)
|
||||
return super(BlogConfigAdmin, self).save_model(request, obj, form, change)
|
||||
|
||||
|
||||
admin.site.register(BlogCategory, BlogCategoryAdmin)
|
||||
admin.site.register(Post, PostAdmin)
|
||||
admin.site.register(BlogConfig, BlogConfigAdmin)
|
||||
|
|
|
@ -139,4 +139,6 @@ class BlogConfigForm(AppDataForm):
|
|||
label=_('Send notifications on post update'), required=False, initial=False,
|
||||
help_text=_('Emits a desktop notification -if enabled- when editing a published post')
|
||||
)
|
||||
|
||||
|
||||
setup_config(BlogConfigForm, BlogConfig)
|
||||
|
|
|
@ -28,5 +28,7 @@ class BlogApp(AutoCMSAppMixin, CMSConfigApp):
|
|||
'object_name': get_setting('DEFAULT_OBJECT_NAME')
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
apphook_pool.register(BlogApp)
|
||||
BlogApp.setup()
|
||||
|
|
|
@ -106,6 +106,7 @@ class BlogCategoryMenu(CMSAttachMenu):
|
|||
|
||||
return nodes
|
||||
|
||||
|
||||
menu_pool.register_menu(BlogCategoryMenu)
|
||||
|
||||
|
||||
|
@ -161,6 +162,7 @@ class BlogNavModifier(Modifier):
|
|||
node.selected = True
|
||||
return nodes
|
||||
|
||||
|
||||
menu_pool.register_modifier(BlogNavModifier)
|
||||
|
||||
|
||||
|
@ -170,5 +172,6 @@ def clear_menu_cache(**kwargs):
|
|||
"""
|
||||
menu_pool.clear(all=True)
|
||||
|
||||
|
||||
post_save.connect(clear_menu_cache, sender=BlogCategory)
|
||||
post_delete.connect(clear_menu_cache, sender=BlogCategory)
|
||||
|
|
|
@ -28,4 +28,5 @@ class LiveblogPlugin(TextPlugin):
|
|||
context['instance'] = instance
|
||||
return context
|
||||
|
||||
|
||||
plugin_pool.register_plugin(LiveblogPlugin)
|
||||
|
|
|
@ -20,6 +20,7 @@ def get_urls():
|
|||
)
|
||||
return details
|
||||
|
||||
|
||||
detail_urls = get_urls()
|
||||
|
||||
urlpatterns = [
|
||||
|
|
Loading…
Reference in a new issue