-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #319 from nephila/feature/cms_342
More django CMS 3.4 compatiblity
- Loading branch information
Showing
8 changed files
with
113 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters