diff --git a/content_plugins/admin.py b/content_plugins/admin.py index 45a126b..5461e9d 100644 --- a/content_plugins/admin.py +++ b/content_plugins/admin.py @@ -13,6 +13,8 @@ class ContentInlineBase(ContentEditorInline): """ +# TODO Use feincms3.plugins.richtext.RichText/RichTextInline instead + class RichTextarea(forms.Textarea): def __init__(self, attrs=None): # Provide class so that the code in plugin_ckeditor.js knows diff --git a/content_plugins/apps.py b/content_plugins/apps.py index 3a9bd48..8ecac6e 100644 --- a/content_plugins/apps.py +++ b/content_plugins/apps.py @@ -1,5 +1,5 @@ from django.apps import AppConfig -class ContentConfig(AppConfig): - name = 'content' +class ContentPluginsConfig(AppConfig): + name = 'content_plugins' diff --git a/content_plugins/abstract_plugins.py b/content_plugins/base.py similarity index 98% rename from content_plugins/abstract_plugins.py rename to content_plugins/base.py index c52a6d5..2ab5fe4 100644 --- a/content_plugins/abstract_plugins.py +++ b/content_plugins/base.py @@ -1,8 +1,4 @@ -# TODO Always use Django templates for rendering, replace .format() class - -import os import re -from django.conf import settings from django.db import models from django.template import Template from django.utils.html import format_html, mark_safe @@ -275,6 +271,7 @@ class FootnoteBase(BasePlugin): return mark_safe(template.format(**context)) +# FIXME Currently doesn't do anything class RichTextFootnoteMixin: MATCH_FOOTNOTES = re.compile("(\w+)") diff --git a/content_plugins/mixins.py b/content_plugins/mixins.py deleted file mode 100644 index a5dc004..0000000 --- a/content_plugins/mixins.py +++ /dev/null @@ -1,97 +0,0 @@ -from functools import reduce, partial -from django.conf import settings -from django.db import models -from django.utils.html import strip_tags -from django.utils.text import normalize_newlines -from django.utils.translation import ugettext_lazy as _ - -from shared.utils.fields import AutoSlugField -from shared.utils.functional import firstof -from shared.utils.text import slimdown - -from . import USE_TRANSLATABLE_FIELDS - - -if USE_TRANSLATABLE_FIELDS: - from shared.multilingual.utils.fields import TranslatableCharField, TranslatableTextField - - -class PageTitlesMixin(models.Model): - """ - A model mixin containg title and slug field for models serving as website - pages with an URL. - """ - # FIXME signals are not sent from abstract models, therefore AutoSlugField doesn't work - if USE_TRANSLATABLE_FIELDS: - short_title = TranslatableCharField(_("Name"), max_length=50) - title = TranslatableTextField(_("Titel (Langform)"), null=True, blank=True, max_length=300) - window_title = TranslatableCharField(_("Fenster-/Suchmaschinentitel"), null=True, blank=True, max_length=300) - # FIXME populate_from should use settings.LANGUAGE - slug = AutoSlugField(_("URL-Name"), max_length=200, populate_from='short_title_de', unique_slug=True, blank=True) - - else: - short_title = models.CharField(_("Name"), max_length=50) - title = models.TextField(_("Titel (Langform)"), null=True, blank=True, max_length=300) - window_title = models.CharField(_("Fenster-/Suchmaschinentitel"), null=True, blank=True, max_length=300) - slug = AutoSlugField(_("URL-Name"), max_length=200, populate_from='short_title', unique_slug=True, blank=True) - - class Meta: - abstract = True - - def __str__(self): - return strip_tags(slimdown(self.short_title)) - - def get_title(self): - return slimdown(firstof( - self.title, - self.short_title - )) - - def get_window_title(self): - return strip_tags(slimdown( - firstof( - self.window_title, - self.short_title, - self.get_first_title_line(), - ) - )) - - def get_first_title_line(self): - """ - First line of title field. - """ - return slimdown( - normalize_newlines(self.get_title()).partition("\n")[0] - ) - - def get_subtitle_lines(self): - """ - All but first line of the long title field. - """ - return slimdown( - normalize_newlines(self.title).partition("\n")[2] - ) - - -# TODO Move to shared.multilingual or shared.utils.translation -def language_variations_for_field(language_codes, fields): - # TODO Check if field is translatable - return ["{}_{}".format(fields, s) for s in language_codes] - - -# TODO Move to shared.multilingual or shared.utils.translation -def language_variations_for_fields(fields, language_codes=None): - if not language_codes: - language_codes = [t[0] for t in settings.LANGUAGES] - f = partial(language_variations_for_field, language_codes) - return reduce(lambda x, y: x + y, map(f, fields)) - - -class PageTitleAdminMixin(object): - search_fields = ['short_title', 'title', 'window_title'] - if USE_TRANSLATABLE_FIELDS: - search_fields = language_variations_for_fields(search_fields) - list_display = ['short_title', 'slug'] - prepopulated_fields = { - 'slug': ('short_title_en',), - }