diff --git a/content_plugins/base.py b/content_plugins/base.py index 5134ba5..df0407a 100644 --- a/content_plugins/base.py +++ b/content_plugins/base.py @@ -1,4 +1,5 @@ import re +from django.core.exceptions import ImproperlyConfigured from django.db import models from django.template import Template from django.utils.html import mark_safe @@ -96,8 +97,8 @@ class StringRendererPlugin(BasePlugin): class FilesystemTemplateRendererPlugin(BasePlugin): - template_name = None template_name_prefix = 'plugins/' + template_name = None class Meta: abstract = True @@ -115,20 +116,14 @@ class FilesystemTemplateRendererPlugin(BasePlugin): then super's template names, finally prefixed _default.html. """ - if getattr(self, 'template_name', False): - template_names = [ - self.template_name, - self.prefixed_path(self.template_name) - ] + if self.template_name is None: + raise ImproperlyConfigured( + "FilesystemTemplateRendererPlugin requires either a definition of " + "'template_name' or an implementation of 'get_template_names()'") else: - template_names = [] - - # TODO Don't call super here, this *is* the file system template plugin - template_names.extend(super().get_template_names() or []) - - return template_names + [ - self.prefixed_path("_default.html") - ] + return [ + self.prefixed_path(self.template_name), + ] class RichTextBase(StyleMixin, FilesystemTemplateRendererPlugin): @@ -137,10 +132,8 @@ class RichTextBase(StyleMixin, FilesystemTemplateRendererPlugin): else: richtext = CleansedRichTextField(_("text"), blank=True) - template_name_prefix = \ - FilesystemTemplateRendererPlugin.template_name_prefix + 'richtext/' - admin_inline_baseclass = RichTextInlineBase + template_name = '_richtext.html' class Meta: abstract = True diff --git a/content_plugins/plugins/mixins.py b/content_plugins/plugins/mixins.py index c05babf..a478e46 100644 --- a/content_plugins/plugins/mixins.py +++ b/content_plugins/plugins/mixins.py @@ -1,22 +1,22 @@ +import os + from django.db import models from django.utils.translation import ugettext_lazy as _ -class StyleMixin(models.Model): - class StyleField(models.CharField): - """ - Allows overriding of STYLE_CHOICES in subclasses. - """ +class StyleField(models.CharField): + """ + Allows overriding of STYLE_CHOICES in subclasses. + """ - def contribute_to_class(self, cls, name, **kwargs): - if hasattr(cls, 'STYLE_CHOICES'): - self.choices = cls.STYLE_CHOICES - super().contribute_to_class(cls, name, **kwargs) + def contribute_to_class(self, cls, name, **kwargs): + if hasattr(cls, 'STYLE_CHOICES'): + self.choices = cls.STYLE_CHOICES + super().contribute_to_class(cls, name, **kwargs) - STYLE_CHOICES = ( - ('default', _("default")), - ) +class StyleMixin(models.Model): + STYLE_CHOICES = tuple() style = StyleField(_("style"), max_length=50, null=True, blank=True) class Meta: @@ -25,25 +25,46 @@ class StyleMixin(models.Model): def get_style_slug(self): return getattr(self, 'style', None) or 'default' - # Compatibiliy with super classes not having a prefixed_path method - def prefixed_path(self, path): - if hasattr(super(), 'prefixed_path'): - return super().prefixed_path(path) - else: - return path + # # Compatibiliy with super classes not having a prefixed_path method + # def prefixed_path(self, path): + # if hasattr(super(), 'prefixed_path'): + # return super().prefixed_path(path) + # else: + # return path + + def add_styled_template_names(self, template_names): + """ + if super().get_template_names(): + [ + "article/_richtext.html", + "_richtext.html", + ] + then add_styled_template_names returns + [ + "article/_richtext/_