From 549cd9e1d7027557fab83dc2709e4141821b5dcf Mon Sep 17 00:00:00 2001 From: Iacopo Spalletti Date: Fri, 26 Aug 2016 08:56:27 +0200 Subject: [PATCH] More django CMS 3.4 compatiblity --- djangocms_blog/cms_app.py | 30 +------- djangocms_blog/cms_apps.py | 32 +++++++++ djangocms_blog/cms_toolbar.py | 70 +----------------- djangocms_blog/cms_toolbars.py | 72 +++++++++++++++++++ .../djangocms_blog/includes/blog_item.html | 6 +- .../templates/djangocms_blog/post_detail.html | 2 +- .../djangocms_blog/post_instant_article.html | 2 +- tests/test_setup.py | 4 +- 8 files changed, 113 insertions(+), 105 deletions(-) create mode 100644 djangocms_blog/cms_apps.py create mode 100644 djangocms_blog/cms_toolbars.py diff --git a/djangocms_blog/cms_app.py b/djangocms_blog/cms_app.py index 62f8780c..8c0899b4 100644 --- a/djangocms_blog/cms_app.py +++ b/djangocms_blog/cms_app.py @@ -1,32 +1,4 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import, print_function, unicode_literals -from aldryn_apphooks_config.app_base import CMSConfigApp -from cms.apphook_pool import apphook_pool -from django.utils.translation import ugettext_lazy as _ -from djangocms_apphook_setup.base import AutoCMSAppMixin - -from .cms_appconfig import BlogConfig -from .menu import BlogCategoryMenu -from .settings import get_setting - - -class BlogApp(AutoCMSAppMixin, CMSConfigApp): - name = _('Blog') - urls = ['djangocms_blog.urls'] - app_name = 'djangocms_blog' - app_config = BlogConfig - menus = [BlogCategoryMenu] - auto_setup = { - 'enabled': get_setting('AUTO_SETUP'), - 'home title': get_setting('AUTO_HOME_TITLE'), - 'page title': get_setting('AUTO_BLOG_TITLE'), - 'namespace': get_setting('AUTO_NAMESPACE'), - 'config_fields': {}, - 'config_translated_fields': { - 'app_title': get_setting('AUTO_APP_TITLE'), - 'object_name': get_setting('DEFAULT_OBJECT_NAME') - }, - } -apphook_pool.register(BlogApp) -BlogApp.setup() +from .cms_apps import * # NOQA diff --git a/djangocms_blog/cms_apps.py b/djangocms_blog/cms_apps.py new file mode 100644 index 00000000..62f8780c --- /dev/null +++ b/djangocms_blog/cms_apps.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- +from __future__ import absolute_import, print_function, unicode_literals + +from aldryn_apphooks_config.app_base import CMSConfigApp +from cms.apphook_pool import apphook_pool +from django.utils.translation import ugettext_lazy as _ +from djangocms_apphook_setup.base import AutoCMSAppMixin + +from .cms_appconfig import BlogConfig +from .menu import BlogCategoryMenu +from .settings import get_setting + + +class BlogApp(AutoCMSAppMixin, CMSConfigApp): + name = _('Blog') + urls = ['djangocms_blog.urls'] + app_name = 'djangocms_blog' + app_config = BlogConfig + menus = [BlogCategoryMenu] + auto_setup = { + 'enabled': get_setting('AUTO_SETUP'), + 'home title': get_setting('AUTO_HOME_TITLE'), + 'page title': get_setting('AUTO_BLOG_TITLE'), + 'namespace': get_setting('AUTO_NAMESPACE'), + 'config_fields': {}, + 'config_translated_fields': { + 'app_title': get_setting('AUTO_APP_TITLE'), + 'object_name': get_setting('DEFAULT_OBJECT_NAME') + }, + } +apphook_pool.register(BlogApp) +BlogApp.setup() diff --git a/djangocms_blog/cms_toolbar.py b/djangocms_blog/cms_toolbar.py index 7dfd2cc4..733681b9 100644 --- a/djangocms_blog/cms_toolbar.py +++ b/djangocms_blog/cms_toolbar.py @@ -1,72 +1,4 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import, print_function, unicode_literals -from cms.toolbar_base import CMSToolbar -from cms.toolbar_pool import toolbar_pool -from cms.utils.urlutils import admin_reverse -from django.core.urlresolvers import reverse -from django.utils.translation import override, ugettext_lazy as _ - -from .settings import get_setting - - -@toolbar_pool.register -class BlogToolbar(CMSToolbar): - - def populate(self): - if (not self.is_current_app and not get_setting('ENABLE_THROUGH_TOOLBAR_MENU')) or \ - not self.request.user.has_perm('djangocms_blog.add_post'): - return # pragma: no cover - admin_menu = self.toolbar.get_or_create_menu('djangocms_blog', _('Blog')) - with override(self.current_lang): - url = reverse('admin:djangocms_blog_post_changelist') - admin_menu.add_modal_item(_('Post list'), url=url) - url = reverse('admin:djangocms_blog_post_add') - admin_menu.add_modal_item(_('Add post'), url=url) - current_config = getattr(self.request, get_setting('CURRENT_NAMESPACE'), None) - if current_config: - url = reverse('admin:djangocms_blog_blogconfig_change', args=(current_config.pk,)) - admin_menu.add_modal_item(_('Edit configuration'), url=url) - - current_post = getattr(self.request, get_setting('CURRENT_POST_IDENTIFIER'), None) - if current_post and self.request.user.has_perm('djangocms_blog.change_post'): # pragma: no cover # NOQA - admin_menu.add_modal_item(_('Edit Post'), reverse( - 'admin:djangocms_blog_post_change', args=(current_post.pk,)), - active=True) - - def add_publish_button(self): - """ - Adds the publish button to the toolbar if the current post is unpublished - """ - current_post = getattr(self.request, get_setting('CURRENT_POST_IDENTIFIER'), None) - if (self.toolbar.edit_mode and current_post and - not current_post.publish and - self.request.user.has_perm('djangocms_blog.change_post') - ): # pragma: no cover # NOQA - classes = ['cms-btn-action', 'blog-publish'] - title = _('Publish {0} now').format(current_post.app_config.object_name) - - url = admin_reverse('djangocms_blog_publish_article', args=(current_post.pk,)) - - self.toolbar.add_button(title, url=url, extra_classes=classes, side=self.toolbar.RIGHT) - - def post_template_populate(self): - current_post = getattr(self.request, get_setting('CURRENT_POST_IDENTIFIER'), None) - if current_post and self.request.user.has_perm('djangocms_blog.change_post'): # pragma: no cover # NOQA - # removing page meta menu, if present, to avoid confusion - try: # pragma: no cover - import djangocms_page_meta # NOQA - menu = self.request.toolbar.get_or_create_menu('page') - pagemeta = menu.get_or_create_menu('pagemeta', 'meta') - menu.remove_item(pagemeta) - except ImportError: - pass - # removing page tags menu, if present, to avoid confusion - try: # pragma: no cover - import djangocms_page_tags # NOQA - menu = self.request.toolbar.get_or_create_menu('page') - pagetags = menu.get_or_create_menu('pagetags', 'tags') - menu.remove_item(pagetags) - except ImportError: - pass - self.add_publish_button() +from .cms_toolbars import * # NOQA diff --git a/djangocms_blog/cms_toolbars.py b/djangocms_blog/cms_toolbars.py new file mode 100644 index 00000000..7dfd2cc4 --- /dev/null +++ b/djangocms_blog/cms_toolbars.py @@ -0,0 +1,72 @@ +# -*- coding: utf-8 -*- +from __future__ import absolute_import, print_function, unicode_literals + +from cms.toolbar_base import CMSToolbar +from cms.toolbar_pool import toolbar_pool +from cms.utils.urlutils import admin_reverse +from django.core.urlresolvers import reverse +from django.utils.translation import override, ugettext_lazy as _ + +from .settings import get_setting + + +@toolbar_pool.register +class BlogToolbar(CMSToolbar): + + def populate(self): + if (not self.is_current_app and not get_setting('ENABLE_THROUGH_TOOLBAR_MENU')) or \ + not self.request.user.has_perm('djangocms_blog.add_post'): + return # pragma: no cover + admin_menu = self.toolbar.get_or_create_menu('djangocms_blog', _('Blog')) + with override(self.current_lang): + url = reverse('admin:djangocms_blog_post_changelist') + admin_menu.add_modal_item(_('Post list'), url=url) + url = reverse('admin:djangocms_blog_post_add') + admin_menu.add_modal_item(_('Add post'), url=url) + current_config = getattr(self.request, get_setting('CURRENT_NAMESPACE'), None) + if current_config: + url = reverse('admin:djangocms_blog_blogconfig_change', args=(current_config.pk,)) + admin_menu.add_modal_item(_('Edit configuration'), url=url) + + current_post = getattr(self.request, get_setting('CURRENT_POST_IDENTIFIER'), None) + if current_post and self.request.user.has_perm('djangocms_blog.change_post'): # pragma: no cover # NOQA + admin_menu.add_modal_item(_('Edit Post'), reverse( + 'admin:djangocms_blog_post_change', args=(current_post.pk,)), + active=True) + + def add_publish_button(self): + """ + Adds the publish button to the toolbar if the current post is unpublished + """ + current_post = getattr(self.request, get_setting('CURRENT_POST_IDENTIFIER'), None) + if (self.toolbar.edit_mode and current_post and + not current_post.publish and + self.request.user.has_perm('djangocms_blog.change_post') + ): # pragma: no cover # NOQA + classes = ['cms-btn-action', 'blog-publish'] + title = _('Publish {0} now').format(current_post.app_config.object_name) + + url = admin_reverse('djangocms_blog_publish_article', args=(current_post.pk,)) + + self.toolbar.add_button(title, url=url, extra_classes=classes, side=self.toolbar.RIGHT) + + def post_template_populate(self): + current_post = getattr(self.request, get_setting('CURRENT_POST_IDENTIFIER'), None) + if current_post and self.request.user.has_perm('djangocms_blog.change_post'): # pragma: no cover # NOQA + # removing page meta menu, if present, to avoid confusion + try: # pragma: no cover + import djangocms_page_meta # NOQA + menu = self.request.toolbar.get_or_create_menu('page') + pagemeta = menu.get_or_create_menu('pagemeta', 'meta') + menu.remove_item(pagemeta) + except ImportError: + pass + # removing page tags menu, if present, to avoid confusion + try: # pragma: no cover + import djangocms_page_tags # NOQA + menu = self.request.toolbar.get_or_create_menu('page') + pagetags = menu.get_or_create_menu('pagetags', 'tags') + menu.remove_item(pagetags) + except ImportError: + pass + self.add_publish_button() diff --git a/djangocms_blog/templates/djangocms_blog/includes/blog_item.html b/djangocms_blog/templates/djangocms_blog/includes/blog_item.html index a9bfc3d6..d4abd158 100644 --- a/djangocms_blog/templates/djangocms_blog/includes/blog_item.html +++ b/djangocms_blog/templates/djangocms_blog/includes/blog_item.html @@ -15,12 +15,12 @@

{{ post.title }}

{% endif %}
{% if not TRUNCWORDS_COUNT %} - {% render_model post "abstract" %} + {% render_model post "abstract" "" "" "safe" %} {% else %} - {% render_model post "abstract" "" "" 'truncatewords_html:TRUNCWORDS_COUNT' %} + {% render_model post "abstract" "" "" "truncatewords_html:TRUNCWORDS_COUNT|safe" %} {% endif %}
- \ No newline at end of file + diff --git a/djangocms_blog/templates/djangocms_blog/post_detail.html b/djangocms_blog/templates/djangocms_blog/post_detail.html index 6c5fc8b2..4645c01b 100644 --- a/djangocms_blog/templates/djangocms_blog/post_detail.html +++ b/djangocms_blog/templates/djangocms_blog/post_detail.html @@ -24,7 +24,7 @@

{% render_model post "title" %}

{% if post.app_config.use_placeholder %}
{% render_placeholder post.content %}
{% else %} -
{% render_model post "post_text" "post_text" %}
+
{% render_model post "post_text" "post_text" "" "safe" %}
{% endif %} {% endblock content_blog %} diff --git a/djangocms_blog/templates/djangocms_blog/post_instant_article.html b/djangocms_blog/templates/djangocms_blog/post_instant_article.html index 96506642..499490d1 100644 --- a/djangocms_blog/templates/djangocms_blog/post_instant_article.html +++ b/djangocms_blog/templates/djangocms_blog/post_instant_article.html @@ -24,7 +24,7 @@

{{ post.abstract|striptags|safe }}

{% if post.app_config.use_placeholder %}
{% render_placeholder post.content %}
{% else %} -
{% render_model post "post_text" "post_text" %}
+
{% render_model post "post_text" "post_text" "" "safe" %}
{% endif %} diff --git a/tests/test_setup.py b/tests/test_setup.py index b09d67af..cfe8691b 100644 --- a/tests/test_setup.py +++ b/tests/test_setup.py @@ -42,7 +42,7 @@ def test_setup_from_url(self): self.assertFalse(BlogConfig.objects.exists()) # importing cms_app triggers the auto setup - from djangocms_blog import cms_app # NOQA + from djangocms_blog import cms_apps # NOQA # Home and blog, published and draft self.assertEqual(Page.objects.count(), 4) @@ -70,7 +70,7 @@ def test_setup_filled(self): home.publish(lang) # importing cms_app triggers the auto setup - from djangocms_blog import cms_app # NOQA + from djangocms_blog import cms_apps # NOQA # Home and blog, published and draft self.assertEqual(Page.objects.count(), 4)