cms.conf.patch: 28 total statements, 0.0% covered

Generated: Wed 2013-03-13 10:33 CET

Source file: /media/Envs/Envs/filer-gallery/lib/python2.7/site-packages/cms/conf/patch.py

Stats: 0 executed, 22 missed, 6 excluded, 34 ignored

  1. # -*- coding: utf-8 -*-
  2. from django.conf import settings
  3. from django.core.exceptions import ImproperlyConfigured
  4. from django.utils.translation import ugettext_lazy as _
  5. from sekizai.helpers import validate_template
  6. from warnings import warn
  7. def pre_patch():
  8. """Patch settings befere adding global cms defaults
  9. """
  10. # append some usefull properties to settings
  11. append_properties = {
  12. 'i18n_installed': 'cms.middleware.multilingual.MultilingualURLMiddleware' in settings.MIDDLEWARE_CLASSES
  13. }
  14. for attr, value in append_properties.items():
  15. if not hasattr(settings, attr):
  16. setattr(settings._wrapped, attr, value)
  17. def post_patch():
  18. """Patch settings after global are adde
  19. """
  20. if settings.CMS_TEMPLATE_INHERITANCE:
  21. # Append the magic inheritance template
  22. settings.CMS_TEMPLATES = tuple(settings.CMS_TEMPLATES) + (
  23. (settings.CMS_TEMPLATE_INHERITANCE_MAGIC, _('Inherit the template of the nearest ancestor')),
  24. )
  25. def post_patch_check():
  26. """Post patch check, just make sure there isn't any misconfiguration. All
  27. the code for checking settings should go here.
  28. """
  29. # Ensure templates are set, and more than just the inheritance setting.
  30. cms_templates_length = len(settings.CMS_TEMPLATES)
  31. if (cms_templates_length < 1 or
  32. (cms_templates_length == 1 and settings.CMS_TEMPLATES[0][0] == settings.CMS_TEMPLATE_INHERITANCE_MAGIC)):
  33. raise ImproperlyConfigured('Please make sure you specified a CMS_TEMPLATES setting.')
  34. # check if is user middleware installed
  35. if settings.CMS_PERMISSION and not 'cms.middleware.user.CurrentUserMiddleware' in settings.MIDDLEWARE_CLASSES:
  36. raise ImproperlyConfigured('CMS Permission system requires cms.middleware.user.CurrentUserMiddleware.\n'
  37. 'Please put it into your MIDDLEWARE_CLASSES in settings file')
  38. # check sekizai namespaces
  39. try:
  40. from django.template.loaders.app_directories import Loader
  41. except ImportError:
  42. return # south...
  43. for template in settings.CMS_TEMPLATES:
  44. if template[0] == settings.CMS_TEMPLATE_INHERITANCE_MAGIC:
  45. continue
  46. if not validate_template(template[0], ['js', 'css']):
  47. raise ImproperlyConfigured(
  48. "The 'js' and 'css' sekizai namespaces must be present in each template, "
  49. "- or a template it inherits from - defined in CMS_TEMPLATES. "
  50. "I can't find the namespaces in %r."
  51. % template[0]
  52. )