diff --git a/AUTHORS.rst b/AUTHORS.rst index 64dfb75..53e4ba9 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -16,6 +16,7 @@ Contributors * cluster-master * danra * Davide Truffo +* Fabian Braun * frnhr * furiousdave * Georgiy Kutsurua diff --git a/cms_helper.py b/cms_helper.py index fd63480..76404b6 100755 --- a/cms_helper.py +++ b/cms_helper.py @@ -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() diff --git a/djangocms_blog/admin.py b/djangocms_blog/admin.py index ce10d10..2230256 100755 --- a/djangocms_blog/admin.py +++ b/djangocms_blog/admin.py @@ -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) diff --git a/djangocms_blog/cms_appconfig.py b/djangocms_blog/cms_appconfig.py index 0ac4542..36ff2cc 100644 --- a/djangocms_blog/cms_appconfig.py +++ b/djangocms_blog/cms_appconfig.py @@ -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) diff --git a/djangocms_blog/cms_apps.py b/djangocms_blog/cms_apps.py index c6e25ae..aad2a18 100644 --- a/djangocms_blog/cms_apps.py +++ b/djangocms_blog/cms_apps.py @@ -28,5 +28,7 @@ class BlogApp(AutoCMSAppMixin, CMSConfigApp): 'object_name': get_setting('DEFAULT_OBJECT_NAME') }, } + + apphook_pool.register(BlogApp) BlogApp.setup() diff --git a/djangocms_blog/cms_menus.py b/djangocms_blog/cms_menus.py index 9cd6e20..89e2b98 100644 --- a/djangocms_blog/cms_menus.py +++ b/djangocms_blog/cms_menus.py @@ -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) diff --git a/djangocms_blog/liveblog/cms_plugins.py b/djangocms_blog/liveblog/cms_plugins.py index 7e0d9fa..c351679 100644 --- a/djangocms_blog/liveblog/cms_plugins.py +++ b/djangocms_blog/liveblog/cms_plugins.py @@ -28,4 +28,5 @@ class LiveblogPlugin(TextPlugin): context['instance'] = instance return context + plugin_pool.register_plugin(LiveblogPlugin) diff --git a/djangocms_blog/urls.py b/djangocms_blog/urls.py index 84b9db2..2d68439 100644 --- a/djangocms_blog/urls.py +++ b/djangocms_blog/urls.py @@ -20,6 +20,7 @@ def get_urls(): ) return details + detail_urls = get_urls() urlpatterns = [