1from django.conf import settings
2from django.core.exceptions import ImproperlyConfigured
3
4from cms.utils.compat.dj import is_installed as app_is_installed
5
6
7def validate_dependencies():
8    """
9    Check for installed apps, their versions and configuration options
10    """
11    if not app_is_installed('treebeard'):
12        raise ImproperlyConfigured('django CMS requires django-treebeard. Please install it and add "treebeard" to INSTALLED_APPS.')
13
14
15def validate_settings():
16    """
17    Check project settings file for required options
18    """
19    try:
20        django_backend = [x for x in settings.TEMPLATES
21                          if x['BACKEND'] == 'django.template.backends.django.DjangoTemplates'][0]
22    except IndexError:
23        raise ImproperlyConfigured("django CMS requires django.template.context_processors.request in "
24                                   "'django.template.backends.django.DjangoTemplates' context processors.")
25
26    context_processors = django_backend.get('OPTIONS', {}).get('context_processors', [])
27    if ('django.core.context_processors.request' not in context_processors and
28            'django.template.context_processors.request' not in context_processors):
29        raise ImproperlyConfigured("django CMS requires django.template.context_processors.request in "
30                                   "'django.template.backends.django.DjangoTemplates' context processors.")
31
32
33def setup():
34    """
35    Gather all checks and validations
36    """
37    from cms.plugin_pool import plugin_pool
38    validate_dependencies()
39    validate_settings()
40    plugin_pool.validate_templates()
41