Skip to content

Commit

Permalink
LUN-1869: Set CMS_TEMPLATES only on exceptional case in SiteIdPatchMi…
Browse files Browse the repository at this point in the history
…ddleware and don't care about interfering in the exception flow (a 404 could possibly be transformed into a 500)
  • Loading branch information
pianas committed Oct 9, 2014
1 parent dadc2ac commit 05e668f
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions cms_templates/middleware.py
Expand Up @@ -57,6 +57,8 @@ def _set_cms_templates_for_request(request):
if not CMS_TEMPLATES.value:
CMS_TEMPLATES.value = [('dummy',
'Please create a template first.')]
CMS_TEMPLATES.value.append((settings.CMS_TEMPLATE_INHERITANCE_MAGIC,
CMS_TEMPLATE_INHERITANCE_TITLE))


class SiteIDPatchMiddleware(object):
Expand All @@ -77,17 +79,10 @@ def process_request(self, request):
logger.warning("SiteIDPatchMiddleware is raising {0}\n\n. "
"Using {1} and bubble up".format(e, self.fallback))
self.fallback.process_request(request)
# any exception raised by the resolver must be raised further
raise e
finally:
# try to set the correct value for CMS_TEMPLATES.
# this ensures we are able to correctly display the CMS error page
try:
_set_cms_templates_for_request(request)
except:
# do not interfere in the normal exception flow, since
# setting the correct CMS_TEMPLATES in this step is optional
pass
_set_cms_templates_for_request(request)
raise e

user = getattr(request, 'user', None)

Expand Down Expand Up @@ -156,6 +151,3 @@ def process_request(self, request):
choices += [(settings.CMS_TEMPLATE_INHERITANCE_MAGIC,
CMS_TEMPLATE_INHERITANCE_TITLE)]
Page._meta.get_field_by_name('template')[0].choices[:] = choices
CMS_TEMPLATES = settings.__class__.CMS_TEMPLATES
CMS_TEMPLATES.value.append((settings.CMS_TEMPLATE_INHERITANCE_MAGIC,
CMS_TEMPLATE_INHERITANCE_TITLE))

0 comments on commit 05e668f

Please sign in to comment.