diff --git a/cms/test_utils/project/templates/inner_dir/custom_templates_2/base.html b/cms/test_utils/project/templates/inner_dir/custom_templates_2/base.html new file mode 100644 index 00000000000..04d31d2a747 --- /dev/null +++ b/cms/test_utils/project/templates/inner_dir/custom_templates_2/base.html @@ -0,0 +1,82 @@ +{% load i18n cms_tags menu_tags sekizai_tags %} + + + + {% page_attribute page_title %} + + + {% render_block "css" %} + + + + +{% cms_toolbar %} +
+ + +
+ {% block content %}{% endblock content %} +
+
+ {% render_block "js" %} + + \ No newline at end of file diff --git a/cms/test_utils/project/templates/inner_dir/custom_templates_2/right_col_three.html b/cms/test_utils/project/templates/inner_dir/custom_templates_2/right_col_three.html new file mode 100644 index 00000000000..6ac7b173f8d --- /dev/null +++ b/cms/test_utils/project/templates/inner_dir/custom_templates_2/right_col_three.html @@ -0,0 +1,32 @@ +{% extends "base.html" %} +{% load i18n cms_tags %} + +{% block tpl_id %}tpl_col_three{% endblock %} + +{% block content %} +

{% render_model request.current_page "page_title" %}

+
+ {% include "sidebar_submenu.html" %} + {% block col_sidebar %} + {% with "220" as width %} + {% placeholder col_sidebar %} + {% endwith %} + {% endblock %} +
+ +
+ {% block col_left %} + {% with "340" as width %} + {% placeholder col_left %} + {% endwith %} + {% endblock %} +
+ +
+ {% block col_right %} + {% with "220" as width %} + {% placeholder col_right %} + {% endwith %} + {% endblock %} +
+{% endblock %} \ No newline at end of file diff --git a/cms/test_utils/project/templates/inner_dir/custom_templates_2/right_col_two.html b/cms/test_utils/project/templates/inner_dir/custom_templates_2/right_col_two.html new file mode 100644 index 00000000000..5448e05442e --- /dev/null +++ b/cms/test_utils/project/templates/inner_dir/custom_templates_2/right_col_two.html @@ -0,0 +1,29 @@ +{% extends "base.html" %} +{% load i18n cms_tags %} + +{% block tpl_id %}tpl_col_two{% endblock %} + +{% block content %} + +

{% render_model request.current_page "titles" %} {% render_model_icon request.current_page %}

+
+ {% render_model request.current_page "menu_title" %} + {% include "sidebar_submenu.html" %} + {% block col_sidebar %} + {% with "220" as width %} + {% placeholder col_sidebar %} + {% endwith %} + {% endblock %} +
+ +
+ {% render_model request.current_page "page_title" %} + {% block col_left %} + {% with "640" as width %} + {% placeholder col_left %} + {% endwith %} + {% endblock %} +
+ + +{% endblock %} \ No newline at end of file diff --git a/cms/test_utils/project/templates/inner_dir/custom_templates_2/templates.ini b/cms/test_utils/project/templates/inner_dir/custom_templates_2/templates.ini new file mode 100644 index 00000000000..83279b72912 --- /dev/null +++ b/cms/test_utils/project/templates/inner_dir/custom_templates_2/templates.ini @@ -0,0 +1,3 @@ +[templates] +right_col_two.html=Two columns +right_col_three.html=Three columns \ No newline at end of file diff --git a/cms/tests/page.py b/cms/tests/page.py index e2f1c247813..f5ee207fa72 100644 --- a/cms/tests/page.py +++ b/cms/tests/page.py @@ -310,7 +310,6 @@ def test_meta_description_from_template_tags(self): req.REQUEST = {} self.assertEqual(t.render(template.Context({"request": req})), "Hello I am a page") - def test_page_obj_change_data_from_template_tags(self): from django import template diff --git a/cms/tests/templates.py b/cms/tests/templates.py index fdcb94a5347..fe28d69436f 100644 --- a/cms/tests/templates.py +++ b/cms/tests/templates.py @@ -1,5 +1,7 @@ # -*- coding: utf-8 -*- import os.path +from cms.test_utils.util.context_managers import SettingsOverride + try: from configparser import ConfigParser except ImportError: @@ -18,6 +20,11 @@ PATH_PREFIX = os.path.join('inner_dir', 'custom_templates') GOOD_PATH = os.path.join(settings.PROJECT_PATH, 'project', 'templates', PATH_PREFIX) BAD_PATH = os.path.join(settings.PROJECT_PATH, 'project', 'custom_templates') +SITE_PATH = { + 1: os.path.join(settings.PROJECT_PATH, 'project', 'templates', PATH_PREFIX), + 2: os.path.join(settings.PROJECT_PATH, 'project', 'templates', '%s_2' % PATH_PREFIX), +} + class TemplatesConfig(CMSTestCase): @@ -65,6 +72,22 @@ def test_custom_templates_loading(self): tpl = loader.get_template(template[0]) self.assertTrue(tpl.name in files) + @override_settings(CMS_TEMPLATES_DIR=SITE_PATH) + def test_multisite(self): + """ + Checking that templates can be loaded by the template loader + """ + templates = get_cms_setting('TEMPLATES') + for template in templates: + if template[0] != constants.TEMPLATE_INHERITANCE_MAGIC: + self.assertTrue(template[0].find('%s/' % SITE_PATH[1]) >= -1) + with SettingsOverride(SITE_ID=2): + templates = get_cms_setting('TEMPLATES') + for template in templates: + if template[0] != constants.TEMPLATE_INHERITANCE_MAGIC: + self.assertTrue(template[0].find('%s/' % SITE_PATH[2]) >= -1) + + @override_settings(CMS_TEMPLATES_DIR=BAD_PATH) def test_custom_templates_bad_dir(self): """ diff --git a/cms/utils/conf.py b/cms/utils/conf.py index 0431bbd2842..f2a645b0548 100644 --- a/cms/utils/conf.py +++ b/cms/utils/conf.py @@ -87,6 +87,10 @@ def get_media_url(): def get_templates(): if getattr(settings, 'CMS_TEMPLATES_DIR', False): tpldir = getattr(settings, 'CMS_TEMPLATES_DIR', False) + # CMS_TEMPLATES_DIR can either be a string poiting to the templates directory + # or a dictionary holding 'site: template dir' entries + if isinstance(tpldir, dict): + tpldir = tpldir[settings.SITE_ID] # We must extract the relative path of CMS_TEMPLATES_DIR to the neares # valid templates directory. Here we mimick what the filesystem and # app_directories template loaders do diff --git a/docs/getting_started/resources/configuration.rst b/docs/getting_started/resources/configuration.rst index 79ba4952401..f5119ffba2e 100644 --- a/docs/getting_started/resources/configuration.rst +++ b/docs/getting_started/resources/configuration.rst @@ -87,9 +87,18 @@ CMS_TEMPLATES_DIR Default: ``None`` Instead of explicitly providing a set of templates via :setting:`CMS_TEMPLATES` -a single directory can be provided using this configuration. +a directory can be provided using this configuration. -The directory is scanned and all templates in it are loaded as templates for +`CMS_TEMPLATES_DIR` can be set to the (absolute) path of the templates directory, +or set to a dictionary with `SITE_ID: template path` items:: + + CMS_TEMPLATES_DIR: { + 1: '/absolute/path/for/site/1/', + 2: '/absolute/path/for/site/2/', + } + + +The provided directory is scanned and all templates in it are loaded as templates for django CMS. Template loaded and their names can be customized using a INI-file called