Move constants from model to settings

Add BLOG_ENABLE_THROUGH_TOOLBAR_MENU setting for controlling toolbar menu appearance
This commit is contained in:
Georgiy Kutsurua 2015-11-22 20:28:54 +04:00
parent 4450f4bc6c
commit 1cf959206d
5 changed files with 20 additions and 10 deletions

View file

@ -366,6 +366,9 @@ Global Settings
* BLOG_SITEMAP_CHANGEFREQ: List for available changefreqs for sitemap items; (default: **always**,
**hourly**, **daily**, **weekly**, **monthly**, **yearly**, **never**)
* BLOG_SITEMAP_CHANGEFREQ_DEFAULT: Default changefreq for sitemap items; (default: ``monthly``)
* BLOG_CURRENT_POST_IDENTIFIER: Current post identifier in request (default ``djangocms_post_current``)
* BLOG_CURRENT_NAMESPACE: Current post config identifier in request (default: ``djangocms_post_current_config``)
* BLOG_ENABLE_THROUGH_TOOLBAR_MENU: Is the toolbar menu throught whole all applications (default: ``False``)
Read-only settings
++++++++++++++++++

View file

@ -6,14 +6,15 @@ from cms.toolbar_pool import toolbar_pool
from django.core.urlresolvers import reverse
from django.utils.translation import override, ugettext_lazy as _
from .models import BLOG_CURRENT_NAMESPACE, BLOG_CURRENT_POST_IDENTIFIER
from .settings import get_setting
@toolbar_pool.register
class BlogToolbar(CMSToolbar):
def populate(self):
if not self.is_current_app or not self.request.user.has_perm('djangocms_blog.add_post'):
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):
@ -21,19 +22,19 @@ class BlogToolbar(CMSToolbar):
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, BLOG_CURRENT_NAMESPACE, None)
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, BLOG_CURRENT_POST_IDENTIFIER, None)
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 post_template_populate(self):
current_post = getattr(self.request, BLOG_CURRENT_POST_IDENTIFIER, None)
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

View file

@ -22,8 +22,8 @@ from .cms_appconfig import BlogConfig
from .managers import GenericDateTaggedManager
from .settings import get_setting
BLOG_CURRENT_POST_IDENTIFIER = 'djangocms_post_current'
BLOG_CURRENT_NAMESPACE = 'djangocms_post_current_config'
BLOG_CURRENT_POST_IDENTIFIER = get_setting('CURRENT_POST_IDENTIFIER')
BLOG_CURRENT_NAMESPACE = get_setting('CURRENT_NAMESPACE')
@python_2_unicode_compatible

View file

@ -101,5 +101,11 @@ def get_setting(name):
),
'BLOG_ENABLE_SEARCH': getattr(settings, 'BLOG_ENABLE_SEARCH', True),
'BLOG_CURRENT_POST_IDENTIFIER': getattr(
settings, 'BLOG_CURRENT_POST_IDENTIFIER', 'djangocms_post_current'),
'BLOG_CURRENT_NAMESPACE': getattr(
settings, 'BLOG_CURRENT_NAMESPACE', 'djangocms_post_current_config'),
'BLOG_ENABLE_THROUGH_TOOLBAR_MENU': getattr(
settings, 'BLOG_ENABLE_THROUGH_TOOLBAR_MENU', False),
}
return default['BLOG_%s' % name]

View file

@ -12,7 +12,7 @@ from django.utils.translation import get_language
from django.views.generic import DetailView, ListView
from parler.views import TranslatableSlugMixin, ViewUrlMixin
from .models import BLOG_CURRENT_NAMESPACE, BLOG_CURRENT_POST_IDENTIFIER, BlogCategory, Post
from .models import BlogCategory, Post
from .settings import get_setting
User = get_user_model()
@ -43,7 +43,7 @@ class BaseBlogView(AppConfigMixin, ViewUrlMixin):
)
if not getattr(self.request, 'toolbar', False) or not self.request.toolbar.edit_mode:
queryset = queryset.published()
setattr(self.request, BLOG_CURRENT_NAMESPACE, self.config)
setattr(self.request, get_setting('CURRENT_NAMESPACE'), self.config)
return queryset
def get_template_names(self):
@ -89,7 +89,7 @@ class PostDetailView(TranslatableSlugMixin, BaseBlogView, DetailView):
context = super(PostDetailView, self).get_context_data(**kwargs)
context['meta'] = self.get_object().as_meta()
context['use_placeholder'] = get_setting('USE_PLACEHOLDER')
setattr(self.request, BLOG_CURRENT_POST_IDENTIFIER, self.get_object())
setattr(self.request, get_setting('CURRENT_POST_IDENTIFIER'), self.get_object())
return context