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 @@
{% block blog_meta %}
+ {% if post.author %}
-
{% trans "by" %} {{ post.author.get_full_name }}
+ {% endif %}
-
{{ post.date_published|date:"M d, Y" }}
diff --git a/djangocms_blog/templates/djangocms_blog/post_detail.html b/djangocms_blog/templates/djangocms_blog/post_detail.html
index 90e03b5..11d63b0 100644
--- a/djangocms_blog/templates/djangocms_blog/post_detail.html
+++ b/djangocms_blog/templates/djangocms_blog/post_detail.html
@@ -13,9 +13,11 @@
{% render_model post "title" %}
{% block blog_meta %}
+ {% if post.author %}
-
{% trans "by" %} {{ post.author.get_full_name }}
+ {% endif %}
-
{{ post.date_published|date:"M d, Y" }}
diff --git a/tests/__init__.py b/tests/__init__.py
index 16b18fc..9531302 100644
--- a/tests/__init__.py
+++ b/tests/__init__.py
@@ -145,6 +145,16 @@ class BaseTest(TestCase):
request.errors = StringIO()
return request
+ def post_request(self, page, lang, data):
+ request = self.request_factory.post(page.get_path(lang), data)
+ request.current_page = page
+ request.user = self.user
+ request.session = {}
+ request.cookies = SimpleCookie()
+ request.errors = StringIO()
+ request._dont_enforce_csrf_checks = True
+ return request
+
def get_page_request(self, page, user, path=None, edit=False, lang_code='en'):
from cms.middleware.toolbar import ToolbarMiddleware
path = path or page and page.get_absolute_url()
diff --git a/tests/test_models.py b/tests/test_models.py
index 8a6948f..713438d 100644
--- a/tests/test_models.py
+++ b/tests/test_models.py
@@ -2,7 +2,9 @@
from cms.api import add_plugin
from cms.utils.copy_plugins import copy_plugins_to
from cms.utils.plugins import downcast_plugins
+from copy import deepcopy
from django.contrib import admin
+from django.contrib.messages.middleware import MessageMiddleware
from django.contrib.sites.models import Site
from django.core.urlresolvers import reverse
from django.utils.timezone import now
@@ -43,6 +45,35 @@ class AdminTest(BaseTest):
fsets = post_admin.get_fieldsets(request)
self.assertTrue('author' in fsets[1][1]['fields'][0])
+ def test_admin_auto_author(self):
+ page1, page2 = self.get_pages()
+ request = self.get_page_request('/', self.user_staff, r'/en/blog/', edit=False)
+ data = deepcopy(self.data['en'][0])
+ data['date_published_0'] = now().strftime('%Y-%m-%d')
+ data['date_published_1'] = now().strftime('%H:%M:%S')
+ data['categories'] = self.category_1.pk
+ request = self.post_request(page1, 'en', data=data)
+ msg_mid = MessageMiddleware()
+ msg_mid.process_request(request)
+ post_admin = admin.site._registry[Post]
+ post_admin.add_view(request)
+ self.assertEqual(Post.objects.count(), 1)
+ self.assertEqual(Post.objects.get(translations__slug='first-post').author_id, 1)
+
+ settings.BLOG_AUTHOR_AUTO = False
+ data = deepcopy(self.data['en'][1])
+ data['date_published_0'] = now().strftime('%Y-%m-%d')
+ data['date_published_1'] = now().strftime('%H:%M:%S')
+ data['categories'] = self.category_1.pk
+ request = self.post_request(page1, 'en', data=data)
+ msg_mid = MessageMiddleware()
+ msg_mid.process_request(request)
+ post_admin = admin.site._registry[Post]
+ post_admin.add_view(request)
+ self.assertEqual(Post.objects.count(), 2)
+ self.assertEqual(Post.objects.get(translations__slug='second-post').author_id, None)
+ settings.BLOG_AUTHOR_AUTO = True
+
class ModelsTest(BaseTest):