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/
)
This commit is contained in:
Fabian Braun 2016-07-06 13:31:58 +02:00
commit 014b94449b
3 changed files with 23 additions and 8 deletions

View file

@ -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)

View file

@ -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

View file

@ -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]