Move autosetup to cms_toolbar
This commit is contained in:
parent
7a839f8e22
commit
4cfb5891f0
3 changed files with 15 additions and 12 deletions
|
@ -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()
|
||||
|
|
|
@ -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<tag>[-\w]+)/feed/$',
|
||||
TagFeed(), name='posts-tagged-feed'),
|
||||
] + detail_urls
|
||||
|
||||
BlogAppConfig.setup()
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue