From 344064dd7c0475d3c0a47dc81e4bce22ff05a6c7 Mon Sep 17 00:00:00 2001 From: Iacopo Spalletti Date: Thu, 10 Mar 2016 00:21:41 +0100 Subject: [PATCH 1/3] When debug is off, swallow AlreadyRegisteredException --- djangocms_blog/cms_wizards.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/djangocms_blog/cms_wizards.py b/djangocms_blog/cms_wizards.py index 1b09965..d4a1717 100644 --- a/djangocms_blog/cms_wizards.py +++ b/djangocms_blog/cms_wizards.py @@ -2,13 +2,14 @@ from __future__ import absolute_import, print_function, unicode_literals from cms.utils.permissions import get_current_user +from django import forms +from django.conf import settings +from django.utils.text import slugify +from django.utils.translation import ugettext_lazy as _ try: from cms.wizards.wizard_base import Wizard - from cms.wizards.wizard_pool import wizard_pool - from django import forms - from django.utils.text import slugify - from django.utils.translation import ugettext_lazy as _ + from cms.wizards.wizard_pool import wizard_pool, AlreadyRegisteredException from parler.forms import TranslatableModelForm from .cms_appconfig import BlogConfig @@ -56,7 +57,11 @@ try: model=Post, description=_('Create a new {0} in {1}').format(config.object_name, config.app_title), ) - wizard_pool.register(post_wizard) + try: + wizard_pool.register(post_wizard) + except AlreadyRegisteredException: + if settings.DEBUG: + raise except ImportError: # For django CMS version not supporting wizards just ignore this file pass From f7802308a232762d06c4320bcd6159abb1457289 Mon Sep 17 00:00:00 2001 From: Iacopo Spalletti Date: Thu, 10 Mar 2016 00:24:10 +0100 Subject: [PATCH 2/3] Add documentation --- README.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.rst b/README.rst index b3390d1..055f95f 100644 --- a/README.rst +++ b/README.rst @@ -352,6 +352,10 @@ content types, such as blog posts. For each configured Apphook, a content type is added to the wizard. +Some issues with multiple registrations raising django CMS ``AlreadyRegisteredException`` +hae been reported; to handle these cases gracefully, the exception is swallowed +when Django ``DEBUG == True`` avoiding breaking production websites. In these cases they +wizard may not show up, but the rest will work as intended. .. _settings: From 30d87f0143bc1d6d09f76151370cf5f183e0d88f Mon Sep 17 00:00:00 2001 From: Iacopo Spalletti Date: Thu, 10 Mar 2016 08:56:02 +0100 Subject: [PATCH 3/3] Exclude untestable code --- djangocms_blog/cms_wizards.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/djangocms_blog/cms_wizards.py b/djangocms_blog/cms_wizards.py index d4a1717..12b7bd2 100644 --- a/djangocms_blog/cms_wizards.py +++ b/djangocms_blog/cms_wizards.py @@ -59,7 +59,7 @@ try: ) try: wizard_pool.register(post_wizard) - except AlreadyRegisteredException: + except AlreadyRegisteredException: # pragma: no cover if settings.DEBUG: raise except ImportError: