From 014b94449b4feefc81a997892d21440d88e842b9 Mon Sep 17 00:00:00 2001 From: Fabian Braun Date: Wed, 6 Jul 2016 13:31:58 +0200 Subject: [PATCH 1/8] Feature-add: Plugins have a field that allows to specify a (sub-)folder from which the plugin templates are loaded. Default folder is "plugins". It goes into the "djangocms_blog" template folder (or, if set, the folder named in the app hook). This allows, e.g., different templates for showing a post list as tables, columns, or you name it. New templates have the same names as the standard templates in the "plugins" folder ("latest_entries.html", "authors.html", "tags.html", "categories.html", "archive.html"). The folder options can be defined in a new setting called BLOG_PLUGIN_TEMPLATE_FOLDERS. It's default is "( ("plugins", _("Default template") )" to be compatible with hitherto configurations. To add new templates write in settings.py, e.g., BLOG_PLUGIN_TEMPLATE_FOLDERS = ( ('plugins', _('Default template') ), # reads from "templates/djangocms_blog/plugins/ ('timeline', _('Vertical timeline') ), # reads from "templates/djangocms_blog/vertical/ ('masonry', _('Masonry style') ), # reads from "templates/djangocms_blog/masonry/ ) --- djangocms_blog/cms_plugins.py | 20 ++++++++++++-------- djangocms_blog/models.py | 8 ++++++++ djangocms_blog/settings.py | 3 +++ 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/djangocms_blog/cms_plugins.py b/djangocms_blog/cms_plugins.py index 70bb4b5..91dac35 100644 --- a/djangocms_blog/cms_plugins.py +++ b/djangocms_blog/cms_plugins.py @@ -18,9 +18,13 @@ class BlogPlugin(CMSPluginBase): def get_render_template(self, context, instance, placeholder): if instance.app_config and instance.app_config.template_prefix: - return os.path.join(instance.app_config.template_prefix, self.base_render_template) + return os.path.join(instance.app_config.template_prefix, + instance.template_folder, + self.base_render_template) else: - return os.path.join('djangocms_blog', self.base_render_template) + return os.path.join('djangocms_blog', + instance.template_folder, + self.base_render_template) class BlogLatestEntriesPlugin(BlogPlugin): @@ -34,7 +38,7 @@ class BlogLatestEntriesPlugin(BlogPlugin): filter_horizontal = ('categories',) fields = ('app_config', 'latest_posts', 'tags', 'categories') cache = False - base_render_template = 'plugins/latest_entries.html' + base_render_template = 'latest_entries.html' def render(self, context, instance, placeholder): context = super(BlogLatestEntriesPlugin, self).render(context, instance, placeholder) @@ -52,7 +56,7 @@ class BlogLatestEntriesPluginCached(BlogPlugin): form = LatestEntriesForm filter_horizontal = ('categories',) fields = ('app_config', 'latest_posts', 'tags', 'categories') - base_render_template = 'plugins/latest_entries.html' + base_render_template = 'latest_entries.html' def render(self, context, instance, placeholder): context = super(BlogLatestEntriesPluginCached, self).render(context, instance, placeholder) @@ -65,7 +69,7 @@ class BlogAuthorPostsPlugin(BlogPlugin): module = get_setting('PLUGIN_MODULE_NAME') name = get_setting('AUTHOR_POSTS_PLUGIN_NAME') model = AuthorEntriesPlugin - base_render_template = 'plugins/authors.html' + base_render_template = 'authors.html' filter_horizontal = ['authors'] def render(self, context, instance, placeholder): @@ -78,7 +82,7 @@ class BlogTagsPlugin(BlogPlugin): module = get_setting('PLUGIN_MODULE_NAME') name = get_setting('TAGS_PLUGIN_NAME') model = GenericBlogPlugin - base_render_template = 'plugins/tags.html' + base_render_template = 'tags.html' def render(self, context, instance, placeholder): context = super(BlogTagsPlugin, self).render(context, instance, placeholder) @@ -91,7 +95,7 @@ class BlogCategoryPlugin(BlogPlugin): module = get_setting('PLUGIN_MODULE_NAME') name = get_setting('CATEGORY_PLUGIN_NAME') model = GenericBlogPlugin - base_render_template = 'plugins/categories.html' + base_render_template = 'categories.html' def render(self, context, instance, placeholder): context = super(BlogCategoryPlugin, self).render(context, instance, placeholder) @@ -111,7 +115,7 @@ class BlogArchivePlugin(BlogPlugin): module = get_setting('PLUGIN_MODULE_NAME') name = get_setting('ARCHIVE_PLUGIN_NAME') model = GenericBlogPlugin - base_render_template = 'plugins/archive.html' + base_render_template = 'archive.html' def render(self, context, instance, placeholder): context = super(BlogArchivePlugin, self).render(context, instance, placeholder) diff --git a/djangocms_blog/models.py b/djangocms_blog/models.py index 91df778..7e040de 100644 --- a/djangocms_blog/models.py +++ b/djangocms_blog/models.py @@ -33,6 +33,7 @@ from .settings import get_setting BLOG_CURRENT_POST_IDENTIFIER = get_setting('CURRENT_POST_IDENTIFIER') BLOG_CURRENT_NAMESPACE = get_setting('CURRENT_NAMESPACE') +BLOG_PLUGIN_TEMPLATE_FOLDERS = get_setting('PLUGIN_TEMPLATE_FOLDERS') try: # pragma: no cover from cmsplugin_filer_image.models import ThumbnailOption # NOQA @@ -378,6 +379,13 @@ class BasePostPlugin(CMSPlugin): current_site = models.BooleanField( _('current site'), default=True, help_text=_('Select items from the current site only') ) + template_folder = models.CharField( + max_length = 40, + verbose_name = _('Plugin template'), + help_text = _('Select plugin template to load for this instance'), + default = BLOG_PLUGIN_TEMPLATE_FOLDERS[0][1], + choices = BLOG_PLUGIN_TEMPLATE_FOLDERS + ) class Meta: abstract = True diff --git a/djangocms_blog/settings.py b/djangocms_blog/settings.py index 0199182..790a1d9 100644 --- a/djangocms_blog/settings.py +++ b/djangocms_blog/settings.py @@ -135,5 +135,8 @@ def get_setting(name): 'BLOG_LIVEBLOG_PLUGINS': getattr( settings, 'BLOG_LIVEBLOG_PLUGINS', ('LiveblogPlugin',)), + 'BLOG_PLUGIN_TEMPLATE_FOLDERS': getattr( + settings, 'BLOG_PLUGIN_TEMPLATE_FOLDERS', (('plugins', _('Default template')),) ), + } return default['BLOG_%s' % name] From dad1569aeabcc92ad6407cf05d13f989ff18257c Mon Sep 17 00:00:00 2001 From: Fabian Braun Date: Wed, 6 Jul 2016 15:40:45 +0200 Subject: [PATCH 2/8] Added: Hide admin interface if only one template is available Added: Migrations --- djangocms_blog/cms_plugins.py | 10 +++++-- .../migrations/0024_auto_20160706_1524.py | 29 +++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 djangocms_blog/migrations/0024_auto_20160706_1524.py diff --git a/djangocms_blog/cms_plugins.py b/djangocms_blog/cms_plugins.py index 91dac35..77cce05 100644 --- a/djangocms_blog/cms_plugins.py +++ b/djangocms_blog/cms_plugins.py @@ -36,7 +36,8 @@ class BlogLatestEntriesPlugin(BlogPlugin): model = LatestPostsPlugin form = LatestEntriesForm filter_horizontal = ('categories',) - fields = ('app_config', 'latest_posts', 'tags', 'categories') + fields = ['app_config', 'latest_posts', 'tags', 'categories'] + \ + ['template_folder'] if len(get_setting('PLUGIN_TEMPLATE_FOLDERS'))>1 else [] cache = False base_render_template = 'latest_entries.html' @@ -55,7 +56,8 @@ class BlogLatestEntriesPluginCached(BlogPlugin): model = LatestPostsPlugin form = LatestEntriesForm filter_horizontal = ('categories',) - fields = ('app_config', 'latest_posts', 'tags', 'categories') + fields = ['app_config', 'latest_posts', 'tags', 'categories']+ \ + ['template_folder'] if len(get_setting('PLUGIN_TEMPLATE_FOLDERS'))>1 else [] base_render_template = 'latest_entries.html' def render(self, context, instance, placeholder): @@ -71,6 +73,7 @@ class BlogAuthorPostsPlugin(BlogPlugin): model = AuthorEntriesPlugin base_render_template = 'authors.html' filter_horizontal = ['authors'] + exclude = ['template_folder'] if len(get_setting('PLUGIN_TEMPLATE_FOLDERS'))>=1 else [] def render(self, context, instance, placeholder): context = super(BlogAuthorPostsPlugin, self).render(context, instance, placeholder) @@ -83,6 +86,7 @@ class BlogTagsPlugin(BlogPlugin): name = get_setting('TAGS_PLUGIN_NAME') model = GenericBlogPlugin base_render_template = 'tags.html' + exclude = ['template_folder'] if len(get_setting('PLUGIN_TEMPLATE_FOLDERS'))>=1 else [] def render(self, context, instance, placeholder): context = super(BlogTagsPlugin, self).render(context, instance, placeholder) @@ -96,6 +100,7 @@ class BlogCategoryPlugin(BlogPlugin): name = get_setting('CATEGORY_PLUGIN_NAME') model = GenericBlogPlugin base_render_template = 'categories.html' + exclude = ['template_folder'] if len(get_setting('PLUGIN_TEMPLATE_FOLDERS'))>=1 else [] def render(self, context, instance, placeholder): context = super(BlogCategoryPlugin, self).render(context, instance, placeholder) @@ -116,6 +121,7 @@ class BlogArchivePlugin(BlogPlugin): name = get_setting('ARCHIVE_PLUGIN_NAME') model = GenericBlogPlugin base_render_template = 'archive.html' + exclude = ['template_folder'] if len(get_setting('PLUGIN_TEMPLATE_FOLDERS'))>=1 else [] def render(self, context, instance, placeholder): context = super(BlogArchivePlugin, self).render(context, instance, placeholder) diff --git a/djangocms_blog/migrations/0024_auto_20160706_1524.py b/djangocms_blog/migrations/0024_auto_20160706_1524.py new file mode 100644 index 0000000..f5eaf57 --- /dev/null +++ b/djangocms_blog/migrations/0024_auto_20160706_1524.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('djangocms_blog', '0023_auto_20160626_1539'), + ] + + operations = [ + migrations.AddField( + model_name='authorentriesplugin', + name='template_folder', + field=models.CharField(default='Default template', verbose_name='Plugin template', max_length=40, help_text='Select plugin template to load for this instance', choices=[('plugins', 'Default template')]), + ), + migrations.AddField( + model_name='genericblogplugin', + name='template_folder', + field=models.CharField(default='Default template', verbose_name='Plugin template', max_length=40, help_text='Select plugin template to load for this instance', choices=[('plugins', 'Default template')]), + ), + migrations.AddField( + model_name='latestpostsplugin', + name='template_folder', + field=models.CharField(default='Default template', verbose_name='Plugin template', max_length=40, help_text='Select plugin template to load for this instance', choices=[('plugins', 'Default template')]), + ), + ] From af2defc46ac8e35d74c1d774ea87b2dc608a2585 Mon Sep 17 00:00:00 2001 From: Fabian Braun Date: Wed, 6 Jul 2016 16:14:22 +0200 Subject: [PATCH 3/8] Brief documentation --- docs/features.rst | 19 +++++++++++++++++++ docs/settings.rst | 3 +++ 2 files changed, 22 insertions(+) diff --git a/docs/features.rst b/docs/features.rst index 55b9f13..261c7a1 100644 --- a/docs/features.rst +++ b/docs/features.rst @@ -149,6 +149,25 @@ To use this feature provide a directory name in **Template prefix** field in the **Apphook configuration** admin (in *Layout* section): it will be the root of your custom templates set. +**************** +Plugin Templates +**************** + +Plugin templates live in the ``plugins`` folder of the folder specified by the **Template prefix**, or by default ``djangocms_blog``. + +By defining the setting ``BLOG_PLUGIN_TEMPLATE_FOLDERS`` you can allow multiple sets of plugin templates allowing for different views per plugin instance. You could, for example, have a plugin displaying latest posts as a list, a table or in masonry style. + +To use this feature define ``BLOG_PLUGIN_TEMPLATE_FOLDERS`` as a list of available templates. Each item of this list itself is a list of the form ``('[folder_name]', '[verbose name]')``. Example: + + BLOG_PLUGIN_TEMPLATE_FOLDERS = ( + ('plugins', _('Default template') ), # reads from "templates/djangocms_blog/plugins/ + ('timeline', _('Vertical timeline') ), # reads from "templates/djangocms_blog/vertical/ + ('masonry', _('Masonry style') ), # reads from "templates/djangocms_blog/masonry/ + ) + + +Once defined, the plugin admin interface will allow content managers to select which template the plugin will use. + .. _sitemap: ******* diff --git a/docs/settings.rst b/docs/settings.rst index 36d658a..8ca94a5 100644 --- a/docs/settings.rst +++ b/docs/settings.rst @@ -91,6 +91,9 @@ Global Settings * BLOG_FEED_INSTANT_ITEMS: Number of items in Instant Article feed * BLOG_FEED_LATEST_ITEMS: Number of items in latest items feed * BLOG_FEED_TAGS_ITEMS: Number of items in per tags feed +* BLOG_PLUGIN_TEMPLATE_FOLDERS: (Sub-)folder from which the plugin templates are loaded. +The default folder is `plugins`. It goes into the `djangocms_blog` template folder (or, if set, the folder named in the app hook). This allows, e.g., different templates for showing a post list as tables, columns, ... . New templates have the same names as the standard templates in the `plugins` folder (`latest_entries.html`, `authors.html`, `tags.html`, `categories.html`, `archive.html`). Default behavior corresponds to this setting being `( ("plugins", _("Default template") )`. To add new templates add to this setting, e.g., `('timeline', _('Vertical timeline') )`. + ****************** Read-only settings From 56cdd5e158bfe98078b3c1c6ff575a7539046eae Mon Sep 17 00:00:00 2001 From: Fabian Braun Date: Wed, 6 Jul 2016 16:24:26 +0200 Subject: [PATCH 4/8] Fix: pep8 improvements --- djangocms_blog/cms_plugins.py | 10 +++++----- djangocms_blog/models.py | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/djangocms_blog/cms_plugins.py b/djangocms_blog/cms_plugins.py index 77cce05..f9d1736 100644 --- a/djangocms_blog/cms_plugins.py +++ b/djangocms_blog/cms_plugins.py @@ -37,7 +37,7 @@ class BlogLatestEntriesPlugin(BlogPlugin): form = LatestEntriesForm filter_horizontal = ('categories',) fields = ['app_config', 'latest_posts', 'tags', 'categories'] + \ - ['template_folder'] if len(get_setting('PLUGIN_TEMPLATE_FOLDERS'))>1 else [] + ['template_folder'] if len(get_setting('PLUGIN_TEMPLATE_FOLDERS')) > 1 else [] cache = False base_render_template = 'latest_entries.html' @@ -56,8 +56,8 @@ class BlogLatestEntriesPluginCached(BlogPlugin): model = LatestPostsPlugin form = LatestEntriesForm filter_horizontal = ('categories',) - fields = ['app_config', 'latest_posts', 'tags', 'categories']+ \ - ['template_folder'] if len(get_setting('PLUGIN_TEMPLATE_FOLDERS'))>1 else [] + fields = ['app_config', 'latest_posts', 'tags', 'categories'] + \ + ['template_folder'] if len(get_setting('PLUGIN_TEMPLATE_FOLDERS')) > 1 else [] base_render_template = 'latest_entries.html' def render(self, context, instance, placeholder): @@ -73,7 +73,7 @@ class BlogAuthorPostsPlugin(BlogPlugin): model = AuthorEntriesPlugin base_render_template = 'authors.html' filter_horizontal = ['authors'] - exclude = ['template_folder'] if len(get_setting('PLUGIN_TEMPLATE_FOLDERS'))>=1 else [] + exclude = ['template_folder'] if len(get_setting('PLUGIN_TEMPLATE_FOLDERS')) >= 1 else [] def render(self, context, instance, placeholder): context = super(BlogAuthorPostsPlugin, self).render(context, instance, placeholder) @@ -121,7 +121,7 @@ class BlogArchivePlugin(BlogPlugin): name = get_setting('ARCHIVE_PLUGIN_NAME') model = GenericBlogPlugin base_render_template = 'archive.html' - exclude = ['template_folder'] if len(get_setting('PLUGIN_TEMPLATE_FOLDERS'))>=1 else [] + exclude = ['template_folder'] if len(get_setting('PLUGIN_TEMPLATE_FOLDERS')) >= 1 else [] def render(self, context, instance, placeholder): context = super(BlogArchivePlugin, self).render(context, instance, placeholder) diff --git a/djangocms_blog/models.py b/djangocms_blog/models.py index 7e040de..22c5309 100644 --- a/djangocms_blog/models.py +++ b/djangocms_blog/models.py @@ -380,11 +380,11 @@ class BasePostPlugin(CMSPlugin): _('current site'), default=True, help_text=_('Select items from the current site only') ) template_folder = models.CharField( - max_length = 40, - verbose_name = _('Plugin template'), - help_text = _('Select plugin template to load for this instance'), - default = BLOG_PLUGIN_TEMPLATE_FOLDERS[0][1], - choices = BLOG_PLUGIN_TEMPLATE_FOLDERS + max_length=40, + verbose_name=_('Plugin template'), + help_text=_('Select plugin template to load for this instance'), + default=BLOG_PLUGIN_TEMPLATE_FOLDERS[0][1], + choices=BLOG_PLUGIN_TEMPLATE_FOLDERS ) class Meta: From 2fa7ebb3b1930a64be6a900710fed6fcdb3bb2cc Mon Sep 17 00:00:00 2001 From: Fabian Braun Date: Thu, 7 Jul 2016 00:01:51 +0200 Subject: [PATCH 5/8] Bugfix: Defaut values for template_folder from settings Bugfix: Extend template_folder length to 200 (including update of migrations) --- djangocms_blog/migrations/0024_auto_20160706_1524.py | 6 +++--- djangocms_blog/models.py | 4 ++-- djangocms_blog/settings.py | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/djangocms_blog/migrations/0024_auto_20160706_1524.py b/djangocms_blog/migrations/0024_auto_20160706_1524.py index f5eaf57..bd658c8 100644 --- a/djangocms_blog/migrations/0024_auto_20160706_1524.py +++ b/djangocms_blog/migrations/0024_auto_20160706_1524.py @@ -14,16 +14,16 @@ class Migration(migrations.Migration): migrations.AddField( model_name='authorentriesplugin', name='template_folder', - field=models.CharField(default='Default template', verbose_name='Plugin template', max_length=40, help_text='Select plugin template to load for this instance', choices=[('plugins', 'Default template')]), + field=models.CharField(default='Default template', verbose_name='Plugin template', max_length=200, help_text='Select plugin template to load for this instance', choices=[('plugins', 'Default template')]), ), migrations.AddField( model_name='genericblogplugin', name='template_folder', - field=models.CharField(default='Default template', verbose_name='Plugin template', max_length=40, help_text='Select plugin template to load for this instance', choices=[('plugins', 'Default template')]), + field=models.CharField(default='Default template', verbose_name='Plugin template', max_length=200, help_text='Select plugin template to load for this instance', choices=[('plugins', 'Default template')]), ), migrations.AddField( model_name='latestpostsplugin', name='template_folder', - field=models.CharField(default='Default template', verbose_name='Plugin template', max_length=40, help_text='Select plugin template to load for this instance', choices=[('plugins', 'Default template')]), + field=models.CharField(default='Default template', verbose_name='Plugin template', max_length=200, help_text='Select plugin template to load for this instance', choices=[('plugins', 'Default template')]), ), ] diff --git a/djangocms_blog/models.py b/djangocms_blog/models.py index 22c5309..1bd1df5 100644 --- a/djangocms_blog/models.py +++ b/djangocms_blog/models.py @@ -380,10 +380,10 @@ class BasePostPlugin(CMSPlugin): _('current site'), default=True, help_text=_('Select items from the current site only') ) template_folder = models.CharField( - max_length=40, + max_length=200, verbose_name=_('Plugin template'), help_text=_('Select plugin template to load for this instance'), - default=BLOG_PLUGIN_TEMPLATE_FOLDERS[0][1], + default=BLOG_PLUGIN_TEMPLATE_FOLDERS[0][0], choices=BLOG_PLUGIN_TEMPLATE_FOLDERS ) diff --git a/djangocms_blog/settings.py b/djangocms_blog/settings.py index 790a1d9..30fc346 100644 --- a/djangocms_blog/settings.py +++ b/djangocms_blog/settings.py @@ -136,7 +136,7 @@ def get_setting(name): settings, 'BLOG_LIVEBLOG_PLUGINS', ('LiveblogPlugin',)), 'BLOG_PLUGIN_TEMPLATE_FOLDERS': getattr( - settings, 'BLOG_PLUGIN_TEMPLATE_FOLDERS', (('plugins', _('Default template')),) ), + settings, 'BLOG_PLUGIN_TEMPLATE_FOLDERS', (('plugins', _('Default template')),)), } return default['BLOG_%s' % name] From a224fcca2e74161dccccde046bb0790f9a98769d Mon Sep 17 00:00:00 2001 From: Fabian Braun Date: Thu, 7 Jul 2016 14:20:40 +0200 Subject: [PATCH 6/8] pep8 corrections --- djangocms_blog/cms_plugins.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/djangocms_blog/cms_plugins.py b/djangocms_blog/cms_plugins.py index f9d1736..637cf18 100644 --- a/djangocms_blog/cms_plugins.py +++ b/djangocms_blog/cms_plugins.py @@ -86,7 +86,7 @@ class BlogTagsPlugin(BlogPlugin): name = get_setting('TAGS_PLUGIN_NAME') model = GenericBlogPlugin base_render_template = 'tags.html' - exclude = ['template_folder'] if len(get_setting('PLUGIN_TEMPLATE_FOLDERS'))>=1 else [] + exclude = ['template_folder'] if len(get_setting('PLUGIN_TEMPLATE_FOLDERS')) >= 1 else [] def render(self, context, instance, placeholder): context = super(BlogTagsPlugin, self).render(context, instance, placeholder) @@ -100,7 +100,7 @@ class BlogCategoryPlugin(BlogPlugin): name = get_setting('CATEGORY_PLUGIN_NAME') model = GenericBlogPlugin base_render_template = 'categories.html' - exclude = ['template_folder'] if len(get_setting('PLUGIN_TEMPLATE_FOLDERS'))>=1 else [] + exclude = ['template_folder'] if len(get_setting('PLUGIN_TEMPLATE_FOLDERS')) >= 1 else [] def render(self, context, instance, placeholder): context = super(BlogCategoryPlugin, self).render(context, instance, placeholder) From 18959d35dffad450b7448fb5fd40762b3623a580 Mon Sep 17 00:00:00 2001 From: Fabian Braun Date: Thu, 7 Jul 2016 15:23:22 +0200 Subject: [PATCH 7/8] Fix: Added and adjusted test_template --- docs/features.rst | 13 ++++++------- tests/test_plugins.py | 11 +++++++++-- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/docs/features.rst b/docs/features.rst index 261c7a1..f7a3e4e 100644 --- a/docs/features.rst +++ b/docs/features.rst @@ -155,16 +155,15 @@ Plugin Templates Plugin templates live in the ``plugins`` folder of the folder specified by the **Template prefix**, or by default ``djangocms_blog``. -By defining the setting ``BLOG_PLUGIN_TEMPLATE_FOLDERS`` you can allow multiple sets of plugin templates allowing for different views per plugin instance. You could, for example, have a plugin displaying latest posts as a list, a table or in masonry style. +By defining the setting ``BLOG_PLUGIN_TEMPLATE_FOLDERS`` you can allow multiple sets of plugin templates allowing for different views per plugin instance. You could, for example, have a plugin displaying latest posts as a list, a table or in masonry style. To use this feature define ``BLOG_PLUGIN_TEMPLATE_FOLDERS`` as a list of available templates. Each item of this list itself is a list of the form ``('[folder_name]', '[verbose name]')``. Example: - BLOG_PLUGIN_TEMPLATE_FOLDERS = ( - ('plugins', _('Default template') ), # reads from "templates/djangocms_blog/plugins/ - ('timeline', _('Vertical timeline') ), # reads from "templates/djangocms_blog/vertical/ - ('masonry', _('Masonry style') ), # reads from "templates/djangocms_blog/masonry/ - ) - + BLOG_PLUGIN_TEMPLATE_FOLDERS = ( + ('plugins', _('Default template')), # reads from templates/djangocms_blog/plugins/ + ('timeline', _('Vertical timeline')), # reads from templates/djangocms_blog/vertical/ + ('masonry', _('Masonry style')), # reads from templates/djangocms_blog/masonry/ + ) Once defined, the plugin admin interface will allow content managers to select which template the plugin will use. diff --git a/tests/test_plugins.py b/tests/test_plugins.py index e926fe4..7ef7202 100644 --- a/tests/test_plugins.py +++ b/tests/test_plugins.py @@ -189,11 +189,18 @@ class PluginTest(BaseTest): context = self.get_plugin_context(pages[0], 'en', plugin) plugin_class = plugin.get_plugin_class_instance() - self.assertEqual(plugin_class.get_render_template(context, plugin, ph), os.path.join('djangocms_blog', plugin_class.base_render_template)) + self.assertEqual(plugin_class.get_render_template(context, plugin, ph), + os.path.join('djangocms_blog', plugin.template_folder, plugin_class.base_render_template)) self.app_config_1.app_data.config.template_prefix = 'whatever' self.app_config_1.save() - self.assertEqual(plugin_class.get_render_template(context, plugin, ph), os.path.join('whatever', plugin_class.base_render_template)) + tmp = plugin.template_folder + plugin.template_folder = 'whereever' + plugin.save() + self.assertEqual(plugin_class.get_render_template(context, plugin, ph), + os.path.join('whatever', 'whereever', plugin_class.base_render_template)) + plugin.template_folder = tmp + plugin.save() self.app_config_1.app_data.config.template_prefix = '' self.app_config_1.save() From 61b2304164e3be99c4b0c9e805ff29c1dfb428f1 Mon Sep 17 00:00:00 2001 From: Fabian Braun Date: Thu, 7 Jul 2016 17:59:32 +0200 Subject: [PATCH 8/8] Fix: Added missing ":" in documentation --- docs/features.rst | 12 +++++++++--- docs/settings.rst | 3 +-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/docs/features.rst b/docs/features.rst index f7a3e4e..bf46071 100644 --- a/docs/features.rst +++ b/docs/features.rst @@ -153,11 +153,17 @@ root of your custom templates set. Plugin Templates **************** -Plugin templates live in the ``plugins`` folder of the folder specified by the **Template prefix**, or by default ``djangocms_blog``. +Plugin templates live in the ``plugins`` folder of the folder specified by the **Template prefix**, +or by default ``djangocms_blog``. -By defining the setting ``BLOG_PLUGIN_TEMPLATE_FOLDERS`` you can allow multiple sets of plugin templates allowing for different views per plugin instance. You could, for example, have a plugin displaying latest posts as a list, a table or in masonry style. +By defining the setting ``BLOG_PLUGIN_TEMPLATE_FOLDERS`` you can allow multiple sets of +plugin templates allowing for different views per plugin instance. You could, for example, +have a plugin displaying latest posts as a list, a table or in masonry style. -To use this feature define ``BLOG_PLUGIN_TEMPLATE_FOLDERS`` as a list of available templates. Each item of this list itself is a list of the form ``('[folder_name]', '[verbose name]')``. Example: +To use this feature define ``BLOG_PLUGIN_TEMPLATE_FOLDERS`` as a list of available templates. +Each item of this list itself is a list of the form ``('[folder_name]', '[verbose name]')``. + +Example::: BLOG_PLUGIN_TEMPLATE_FOLDERS = ( ('plugins', _('Default template')), # reads from templates/djangocms_blog/plugins/ diff --git a/docs/settings.rst b/docs/settings.rst index 8ca94a5..b3f0afe 100644 --- a/docs/settings.rst +++ b/docs/settings.rst @@ -91,8 +91,7 @@ Global Settings * BLOG_FEED_INSTANT_ITEMS: Number of items in Instant Article feed * BLOG_FEED_LATEST_ITEMS: Number of items in latest items feed * BLOG_FEED_TAGS_ITEMS: Number of items in per tags feed -* BLOG_PLUGIN_TEMPLATE_FOLDERS: (Sub-)folder from which the plugin templates are loaded. -The default folder is `plugins`. It goes into the `djangocms_blog` template folder (or, if set, the folder named in the app hook). This allows, e.g., different templates for showing a post list as tables, columns, ... . New templates have the same names as the standard templates in the `plugins` folder (`latest_entries.html`, `authors.html`, `tags.html`, `categories.html`, `archive.html`). Default behavior corresponds to this setting being `( ("plugins", _("Default template") )`. To add new templates add to this setting, e.g., `('timeline', _('Vertical timeline') )`. +* BLOG_PLUGIN_TEMPLATE_FOLDERS: (Sub-)folder from which the plugin templates are loaded. The default folder is ``plugins``. It goes into the ``djangocms_blog`` template folder (or, if set, the folder named in the app hook). This allows, e.g., different templates for showing a post list as tables, columns, ... . New templates have the same names as the standard templates in the ``plugins`` folder (``latest_entries.html``, ``authors.html``, ``tags.html``, ``categories.html``, ``archive.html``). Default behavior corresponds to this setting being ``( ("plugins", _("Default template") )``. To add new templates add to this setting, e.g., ``('timeline', _('Vertical timeline') )``. ******************