From 12f2544ad51f1e840ae084305528887bf9153315 Mon Sep 17 00:00:00 2001 From: Iacopo Spalletti Date: Sat, 26 Mar 2016 01:19:25 +0100 Subject: [PATCH 1/5] Minor code reorg --- djangocms_blog/models.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/djangocms_blog/models.py b/djangocms_blog/models.py index f85848a..2ce9a43 100644 --- a/djangocms_blog/models.py +++ b/djangocms_blog/models.py @@ -188,6 +188,11 @@ class Post(ModelMeta, TranslatableModel): def __str__(self): return self.safe_translation_getter('title') + def save_translation(self, translation, *args, **kwargs): + if not translation.slug and translation.title: + translation.slug = slugify(translation.title) + super(Post, self).save_translation(translation, *args, **kwargs) + def get_absolute_url(self, lang=None): if not lang: lang = get_language() @@ -227,11 +232,6 @@ class Post(ModelMeta, TranslatableModel): data = value return data - def save_translation(self, translation, *args, **kwargs): - if not translation.slug and translation.title: - translation.slug = slugify(translation.title) - super(Post, self).save_translation(translation, *args, **kwargs) - def get_title(self): title = self.safe_translation_getter('meta_title', any_language=True) if not title: From 30ea472372bac22b134d42d21a10a3cc7b59ce23 Mon Sep 17 00:00:00 2001 From: Iacopo Spalletti Date: Sat, 26 Mar 2016 01:19:49 +0100 Subject: [PATCH 2/5] Add is_published property --- djangocms_blog/models.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/djangocms_blog/models.py b/djangocms_blog/models.py index 2ce9a43..0015991 100644 --- a/djangocms_blog/models.py +++ b/djangocms_blog/models.py @@ -285,6 +285,13 @@ class Post(ModelMeta, TranslatableModel): def get_full_url(self): return self.build_absolute_uri(self.get_absolute_url()) + @property + def is_published(self): + return (self.publish and + (self.date_published and self.date_published <= timezone.now()) and + (self.date_published_end is None or self.date_published_end > timezone.now()) + ) + class BasePostPlugin(CMSPlugin): app_config = AppHookConfigField( From 3677129423c03f79fb040e3133d50cd6b727d0b3 Mon Sep 17 00:00:00 2001 From: Iacopo Spalletti Date: Sat, 26 Mar 2016 01:20:14 +0100 Subject: [PATCH 3/5] Add django-knocker support --- djangocms_blog/models.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/djangocms_blog/models.py b/djangocms_blog/models.py index 0015991..4e9b332 100644 --- a/djangocms_blog/models.py +++ b/djangocms_blog/models.py @@ -33,6 +33,12 @@ except ImportError: from cmsplugin_filer_image.models import ThumbnailOption # NOQA thumbnail_model = 'cmsplugin_filer_image.ThumbnailOption' +try: + from knocker.mixins import KnockerModel +except ImportError: + class KnockerModel(object): + pass + @python_2_unicode_compatible class BlogCategory(TranslatableModel): @@ -91,7 +97,7 @@ class BlogCategory(TranslatableModel): @python_2_unicode_compatible -class Post(ModelMeta, TranslatableModel): +class Post(KnockerModel, ModelMeta, TranslatableModel): """ Blog post """ From 6c7e1b72f818e10cd4ab38c591bf3362b442b994 Mon Sep 17 00:00:00 2001 From: Iacopo Spalletti Date: Sat, 26 Mar 2016 01:25:40 +0100 Subject: [PATCH 4/5] Update docs --- HISTORY.rst | 5 +++++ README.rst | 9 +++++++++ djangocms_blog/models.py | 6 ++++++ 3 files changed, 20 insertions(+) diff --git a/HISTORY.rst b/HISTORY.rst index 4611579..98dcaad 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -3,6 +3,11 @@ History ------- +0.7.1 (unreleased) +++++++++++++++++++ + +* Add django-knocker integration + 0.7.0 (2016-03-19) ++++++++++++++++++ diff --git a/README.rst b/README.rst index 63957ad..38671f3 100644 --- a/README.rst +++ b/README.rst @@ -357,6 +357,15 @@ hae been reported; to handle these cases gracefully, the exception is swallowed when Django ``DEBUG == True`` avoiding breaking production websites. In these cases they wizard may not show up, but the rest will work as intended. +django-knocker +++++++++++++++ + +``djangocms-blog`` is integrated with `django-knocker `_ +to provide real time desktop notifications. + +See `django-knocker documentation `_ for how to configure +knocker. + .. _settings: Global Settings diff --git a/djangocms_blog/models.py b/djangocms_blog/models.py index 4e9b332..9d4503c 100644 --- a/djangocms_blog/models.py +++ b/djangocms_blog/models.py @@ -37,6 +37,9 @@ try: from knocker.mixins import KnockerModel except ImportError: class KnockerModel(object): + """ + Stub class if django-knocker is not installed + """ pass @@ -293,6 +296,9 @@ class Post(KnockerModel, ModelMeta, TranslatableModel): @property def is_published(self): + """ + Checks wether the blog post is *really* published by checking publishing dates too + """ return (self.publish and (self.date_published and self.date_published <= timezone.now()) and (self.date_published_end is None or self.date_published_end > timezone.now()) From 5868a9facebe23fbc8a9a90c8b6f2603c5015676 Mon Sep 17 00:00:00 2001 From: Iacopo Spalletti Date: Sat, 26 Mar 2016 11:55:20 +0100 Subject: [PATCH 5/5] Improve tests --- tests/test_models.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/tests/test_models.py b/tests/test_models.py index 5b28745..11a8f34 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -3,6 +3,7 @@ from __future__ import absolute_import, print_function, unicode_literals import re from copy import deepcopy +from datetime import timedelta import parler from cms.api import add_plugin @@ -335,6 +336,47 @@ class ModelsTest(BaseTest): post.meta_title = 'meta title' self.assertEqual(post.get_title(), 'meta title') + # Assess is_published property + post.publish = False + post.save() + self.assertFalse(post.is_published) + + post.publish = True + post.date_published = now() + timedelta(days=1) + post.date_published_end = None + post.save() + self.assertFalse(post.is_published) + + post.publish = True + post.date_published = now() - timedelta(days=1) + post.date_published_end = now() - timedelta(minutes=1) + post.save() + self.assertFalse(post.is_published) + + post.publish = True + post.date_published = now() - timedelta(days=1) + post.date_published_end = None + post.save() + self.assertTrue(post.is_published) + + post.publish = True + post.date_published = now() - timedelta(days=1) + post.date_published_end = now() + timedelta(minutes=1) + post.save() + self.assertTrue(post.is_published) + + post.publish = False + post.date_published = now() - timedelta(days=1) + post.date_published_end = None + post.save() + self.assertFalse(post.is_published) + + post.publish = False + post.date_published = now() - timedelta(days=1) + post.date_published_end = now() + timedelta(minutes=1) + post.save() + self.assertFalse(post.is_published) + def test_urls(self): self.get_pages() post = self._get_post(self._post_data[0]['en'])