More django CMS 3.4 compatiblity

This commit is contained in:
Iacopo Spalletti 2016-08-26 08:56:27 +02:00
parent 479cd067c7
commit 549cd9e1d7
No known key found for this signature in database
GPG key ID: BDCBC2EB289F60C6
8 changed files with 113 additions and 105 deletions

View file

@ -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

View file

@ -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()

View file

@ -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

View file

@ -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()

View file

@ -15,12 +15,12 @@
{% 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>

View file

@ -24,7 +24,7 @@
{% 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 %}

View file

@ -24,7 +24,7 @@
{% 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>

View file

@ -42,7 +42,7 @@ class SetupTest(BaseTest):
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)
@ -70,7 +70,7 @@ class SetupTest(BaseTest):
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)