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]