From 4cfb5891f0ae568ef21ee5cef86aecddbd775499 Mon Sep 17 00:00:00 2001 From: Iacopo Spalletti Date: Fri, 23 Oct 2015 07:25:57 +0200 Subject: [PATCH] Move autosetup to cms_toolbar --- djangocms_blog/cms_toolbar.py | 6 ++++-- djangocms_blog/urls.py | 3 --- tests/test_setup.py | 18 +++++++++++------- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/djangocms_blog/cms_toolbar.py b/djangocms_blog/cms_toolbar.py index 0cbddc6..d42fed0 100644 --- a/djangocms_blog/cms_toolbar.py +++ b/djangocms_blog/cms_toolbar.py @@ -6,6 +6,7 @@ from cms.toolbar_pool import toolbar_pool from django.core.urlresolvers import reverse from django.utils.translation import override, ugettext_lazy as _ +from .apps import BlogAppConfig from .models import BLOG_CURRENT_NAMESPACE, BLOG_CURRENT_POST_IDENTIFIER @@ -13,8 +14,7 @@ from .models import BLOG_CURRENT_NAMESPACE, BLOG_CURRENT_POST_IDENTIFIER class BlogToolbar(CMSToolbar): def populate(self): - # TODO: Readd if not self.is_current_app condition when CMS 3.0.4 is released - if not self.request.user.has_perm('djangocms_blog.add_post'): + if not self.is_current_app 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): @@ -52,3 +52,5 @@ class BlogToolbar(CMSToolbar): menu.remove_item(pagetags) except ImportError: pass + +BlogAppConfig.setup() diff --git a/djangocms_blog/urls.py b/djangocms_blog/urls.py index 18b9dbd..14ad98f 100644 --- a/djangocms_blog/urls.py +++ b/djangocms_blog/urls.py @@ -3,7 +3,6 @@ from __future__ import absolute_import, print_function, unicode_literals from django.conf.urls import url -from .apps import BlogAppConfig from .feeds import LatestEntriesFeed, TagFeed from .settings import get_setting from .views import ( @@ -41,5 +40,3 @@ urlpatterns = [ url(r'^tag/(?P[-\w]+)/feed/$', TagFeed(), name='posts-tagged-feed'), ] + detail_urls - -BlogAppConfig.setup() diff --git a/tests/test_setup.py b/tests/test_setup.py index 13428fc..b36b6fe 100644 --- a/tests/test_setup.py +++ b/tests/test_setup.py @@ -25,21 +25,25 @@ class SetupTest(BaseTest): self.assertFalse(Page.objects.exists()) self.assertFalse(BlogConfig.objects.exists()) - # importing urls triggers the auto setup - from djangocms_blog import urls # NOQA + # importing admin triggers the auto setup + from djangocms_blog import cms_toolbar # NOQA # Home and blog, published and draft self.assertEqual(Page.objects.count(), 4) self.assertEqual(BlogConfig.objects.count(), 1) def setUp(self): - self.reload_urlconf() + from cms.toolbar_pool import toolbar_pool + from djangocms_blog import cms_toolbar + + toolbar_pool.unregister(cms_toolbar.BlogToolbar) delete = [ 'djangocms_blog', - 'djangocms_blog.urls', + 'djangocms_blog.cms_toolbar', ] for module in delete: - del sys.modules[module] + if module in sys.modules: + del sys.modules[module] def test_setup_filled(self): @@ -62,8 +66,8 @@ class SetupTest(BaseTest): ) home.publish(lang) - # importing urls triggers the auto setup - from djangocms_blog import urls # NOQA + # importing admin triggers the auto setup + from djangocms_blog import cms_toolbar # NOQA # Home and blog, published and draft self.assertEqual(Page.objects.count(), 4)