Merge pull request #155 from nephila/feature/move_autosetup
Move autosetup to cms_toolbar
This commit is contained in:
commit
b71b104a05
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.core.urlresolvers import reverse
|
||||||
from django.utils.translation import override, ugettext_lazy as _
|
from django.utils.translation import override, ugettext_lazy as _
|
||||||
|
|
||||||
|
from .apps import BlogAppConfig
|
||||||
from .models import BLOG_CURRENT_NAMESPACE, BLOG_CURRENT_POST_IDENTIFIER
|
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):
|
class BlogToolbar(CMSToolbar):
|
||||||
|
|
||||||
def populate(self):
|
def populate(self):
|
||||||
# TODO: Readd if not self.is_current_app condition when CMS 3.0.4 is released
|
if not self.is_current_app or not self.request.user.has_perm('djangocms_blog.add_post'):
|
||||||
if not self.request.user.has_perm('djangocms_blog.add_post'):
|
|
||||||
return # pragma: no cover
|
return # pragma: no cover
|
||||||
admin_menu = self.toolbar.get_or_create_menu('djangocms_blog', _('Blog'))
|
admin_menu = self.toolbar.get_or_create_menu('djangocms_blog', _('Blog'))
|
||||||
with override(self.current_lang):
|
with override(self.current_lang):
|
||||||
|
@ -52,3 +52,5 @@ class BlogToolbar(CMSToolbar):
|
||||||
menu.remove_item(pagetags)
|
menu.remove_item(pagetags)
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
BlogAppConfig.setup()
|
||||||
|
|
|
@ -3,7 +3,6 @@ from __future__ import absolute_import, print_function, unicode_literals
|
||||||
|
|
||||||
from django.conf.urls import url
|
from django.conf.urls import url
|
||||||
|
|
||||||
from .apps import BlogAppConfig
|
|
||||||
from .feeds import LatestEntriesFeed, TagFeed
|
from .feeds import LatestEntriesFeed, TagFeed
|
||||||
from .settings import get_setting
|
from .settings import get_setting
|
||||||
from .views import (
|
from .views import (
|
||||||
|
@ -41,5 +40,3 @@ urlpatterns = [
|
||||||
url(r'^tag/(?P<tag>[-\w]+)/feed/$',
|
url(r'^tag/(?P<tag>[-\w]+)/feed/$',
|
||||||
TagFeed(), name='posts-tagged-feed'),
|
TagFeed(), name='posts-tagged-feed'),
|
||||||
] + detail_urls
|
] + detail_urls
|
||||||
|
|
||||||
BlogAppConfig.setup()
|
|
||||||
|
|
|
@ -25,20 +25,24 @@ class SetupTest(BaseTest):
|
||||||
self.assertFalse(Page.objects.exists())
|
self.assertFalse(Page.objects.exists())
|
||||||
self.assertFalse(BlogConfig.objects.exists())
|
self.assertFalse(BlogConfig.objects.exists())
|
||||||
|
|
||||||
# importing urls triggers the auto setup
|
# importing admin triggers the auto setup
|
||||||
from djangocms_blog import urls # NOQA
|
from djangocms_blog import cms_toolbar # NOQA
|
||||||
|
|
||||||
# Home and blog, published and draft
|
# Home and blog, published and draft
|
||||||
self.assertEqual(Page.objects.count(), 4)
|
self.assertEqual(Page.objects.count(), 4)
|
||||||
self.assertEqual(BlogConfig.objects.count(), 1)
|
self.assertEqual(BlogConfig.objects.count(), 1)
|
||||||
|
|
||||||
def setUp(self):
|
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 = [
|
delete = [
|
||||||
'djangocms_blog',
|
'djangocms_blog',
|
||||||
'djangocms_blog.urls',
|
'djangocms_blog.cms_toolbar',
|
||||||
]
|
]
|
||||||
for module in delete:
|
for module in delete:
|
||||||
|
if module in sys.modules:
|
||||||
del sys.modules[module]
|
del sys.modules[module]
|
||||||
|
|
||||||
def test_setup_filled(self):
|
def test_setup_filled(self):
|
||||||
|
@ -62,8 +66,8 @@ class SetupTest(BaseTest):
|
||||||
)
|
)
|
||||||
home.publish(lang)
|
home.publish(lang)
|
||||||
|
|
||||||
# importing urls triggers the auto setup
|
# importing admin triggers the auto setup
|
||||||
from djangocms_blog import urls # NOQA
|
from djangocms_blog import cms_toolbar # NOQA
|
||||||
|
|
||||||
# Home and blog, published and draft
|
# Home and blog, published and draft
|
||||||
self.assertEqual(Page.objects.count(), 4)
|
self.assertEqual(Page.objects.count(), 4)
|
||||||
|
|
Loading…
Reference in a new issue