Skip to content

Commit

Permalink
Merge pull request #319 from nephila/feature/cms_342
Browse files Browse the repository at this point in the history
More django CMS 3.4 compatiblity
  • Loading branch information
yakky authored Aug 26, 2016
2 parents 479cd06 + 549cd9e commit 2b40378
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 105 deletions.
30 changes: 1 addition & 29 deletions djangocms_blog/cms_app.py
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
32 changes: 32 additions & 0 deletions djangocms_blog/cms_apps.py
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()
70 changes: 1 addition & 69 deletions djangocms_blog/cms_toolbar.py
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
72 changes: 72 additions & 0 deletions djangocms_blog/cms_toolbars.py
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()
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ <h3><a href="{{ post.get_absolute_url }}">{{ post.title }}</a></h3>
{% endif %}
<div class="blog-lead">
{% if not TRUNCWORDS_COUNT %}
{% render_model post "abstract" %}
{% render_model post "abstract" "" "" "safe" %}
{% else %}
{% render_model post "abstract" "" "" 'truncatewords_html:TRUNCWORDS_COUNT' %}
{% render_model post "abstract" "" "" "truncatewords_html:TRUNCWORDS_COUNT|safe" %}
{% endif %}
</div>
<footer class="read-more">
<a href="{{ post.get_absolute_url }}">{% trans "read more" %} &raquo;</a>
</footer>
</article>
</article>
2 changes: 1 addition & 1 deletion djangocms_blog/templates/djangocms_blog/post_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ <h2>{% render_model post "title" %}</h2>
{% if post.app_config.use_placeholder %}
<div class="blog-content">{% render_placeholder post.content %}</div>
{% else %}
<div class="blog-content">{% render_model post "post_text" "post_text" %}</div>
<div class="blog-content">{% render_model post "post_text" "post_text" "" "safe" %}</div>
{% endif %}
</article>
{% endblock content_blog %}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ <h3 class="op-kicker">{{ post.abstract|striptags|safe }}</h3>
{% if post.app_config.use_placeholder %}
<div class="blog-content">{% render_placeholder post.content %}</div>
{% else %}
<div class="blog-content">{% render_model post "post_text" "post_text" %}</div>
<div class="blog-content">{% render_model post "post_text" "post_text" "" "safe" %}</div>
{% endif %}
</article>
</body>
Expand Down
4 changes: 2 additions & 2 deletions tests/test_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test_setup_from_url(self):
self.assertFalse(BlogConfig.objects.exists())

# importing cms_app triggers the auto setup
from djangocms_blog import cms_app # NOQA
from djangocms_blog import cms_apps # NOQA

# Home and blog, published and draft
self.assertEqual(Page.objects.count(), 4)
Expand Down Expand Up @@ -70,7 +70,7 @@ def test_setup_filled(self):
home.publish(lang)

# importing cms_app triggers the auto setup
from djangocms_blog import cms_app # NOQA
from djangocms_blog import cms_apps # NOQA

# Home and blog, published and draft
self.assertEqual(Page.objects.count(), 4)
Expand Down

0 comments on commit 2b40378

Please sign in to comment.