From 2b0bfc010e1b87b2210c84de56bd213d17d270a0 Mon Sep 17 00:00:00 2001 From: Iacopo Spalletti Date: Sat, 11 Oct 2014 09:05:02 +0200 Subject: [PATCH] Make auto adding author optional --- cms_helper.py | 4 +++ djangocms_blog/admin.py | 3 +- djangocms_blog/models.py | 2 ++ djangocms_blog/settings.py | 1 + .../djangocms_blog/includes/blog_item.html | 2 ++ .../templates/djangocms_blog/post_detail.html | 2 ++ tests/__init__.py | 10 ++++++ tests/test_models.py | 31 +++++++++++++++++++ 8 files changed, 54 insertions(+), 1 deletion(-) diff --git a/cms_helper.py b/cms_helper.py index f268fe6..0999553 100644 --- a/cms_helper.py +++ b/cms_helper.py @@ -9,6 +9,7 @@ HELPER_SETTINGS = { ], 'ROOT_URLCONF': 'tests.test_utils.urls', 'INSTALLED_APPS': [ + 'django.contrib.messages', 'admin_enhancer', 'filer', 'parler', @@ -71,6 +72,9 @@ HELPER_SETTINGS = { 'hide_untranslated': False, } }, + 'MIDDLEWARE_CLASSES': [ + 'django.contrib.messages.middleware.MessageMiddleware', + ], 'META_SITE_PROTOCOL': 'http', 'META_SITE_DOMAIN': 'example.com', 'META_USE_OG_PROPERTIES': True, diff --git a/djangocms_blog/admin.py b/djangocms_blog/admin.py index ad7701e..d4475ef 100755 --- a/djangocms_blog/admin.py +++ b/djangocms_blog/admin.py @@ -61,7 +61,8 @@ class PostAdmin(EnhancedModelAdminMixin, FrontendEditableAdmin, return {'slug': ('title',)} def save_model(self, request, obj, form, change): - if not obj.author_id: + from .settings import BLOG_AUTHOR_AUTO + if not obj.author_id and BLOG_AUTHOR_AUTO: obj.author = request.user super(PostAdmin, self).save_model(request, obj, form, change) diff --git a/djangocms_blog/models.py b/djangocms_blog/models.py index 8917e83..0e98aaa 100644 --- a/djangocms_blog/models.py +++ b/djangocms_blog/models.py @@ -180,10 +180,12 @@ class Post(ModelMeta, TranslatableModel): def save(self, *args, **kwargs): super(Post, self).save(*args, **kwargs) + main_lang = self.get_current_language() for lang in self.get_available_languages(): self.set_current_language(lang) if not self.slug and self.title: self.slug = slugify(self.title) + self.set_current_language(main_lang) self.save_translations() def get_absolute_url(self): diff --git a/djangocms_blog/settings.py b/djangocms_blog/settings.py index 707bccf..211fc90 100644 --- a/djangocms_blog/settings.py +++ b/djangocms_blog/settings.py @@ -34,3 +34,4 @@ BLOG_GPLUS_AUTHOR = getattr(settings, 'BLOG_GPLUS_AUTHOR', 'get_author_gplus') BLOG_ENABLE_COMMENTS = getattr(settings, 'BLOG_ENABLE_COMMENTS', True) BLOG_USE_PLACEHOLDER = getattr(settings, 'BLOG_USE_PLACEHOLDER', True) BLOG_MULTISITE = getattr(settings, 'BLOG_MULTISITE', True) +BLOG_AUTHOR_AUTO = getattr(settings, 'BLOG_AUTHOR_AUTO', True) \ No newline at end of file diff --git a/djangocms_blog/templates/djangocms_blog/includes/blog_item.html b/djangocms_blog/templates/djangocms_blog/includes/blog_item.html index f5c2022..e09fc84 100644 --- a/djangocms_blog/templates/djangocms_blog/includes/blog_item.html +++ b/djangocms_blog/templates/djangocms_blog/includes/blog_item.html @@ -6,9 +6,11 @@

{{ post.title }}

{% block blog_meta %}