From 7d173740c881efac445ae477492c491c1f8c872a Mon Sep 17 00:00:00 2001 From: Erik Stein Date: Wed, 11 Jul 2018 18:37:23 +0200 Subject: [PATCH] __str__ method of plugins. --- content_plugins/base.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/content_plugins/base.py b/content_plugins/base.py index df0407a..0e33780 100644 --- a/content_plugins/base.py +++ b/content_plugins/base.py @@ -2,7 +2,8 @@ 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 +from django.utils.html import mark_safe, strip_tags +from django.utils.text import Truncator from django.utils.translation import ugettext_lazy as _ from feincms3.cleanse import CleansedRichTextField @@ -140,6 +141,9 @@ class RichTextBase(StyleMixin, FilesystemTemplateRendererPlugin): verbose_name = _("text") verbose_name_plural = _("texts") + def __str__(self): + return Truncator(strip_tags(self.richtext)).words(10, truncate=" ...") + class SectionBase(StyleMixin, BasePlugin): if USE_TRANSLATABLE_FIELDS: @@ -153,6 +157,9 @@ class SectionBase(StyleMixin, BasePlugin): verbose_name = _("section") verbose_name_plural = _("section") + def __str__(self): + return Truncator(strip_tags(self.subheading)).words(10, truncate=" ...") + def get_template(self): return Template(""" @@ -204,6 +211,9 @@ class DownloadBase(StyleMixin, BasePlugin): verbose_name = _("download") verbose_name_plural = _("downloads") + def __str__(self): + return getattr(self.file, 'name', "") + def render(self): template = """ {name} @@ -229,6 +239,12 @@ class FootnoteBase(BasePlugin): verbose_name = _("footnote") verbose_name_plural = _("footnote") + def __str__(self): + return "[{}] {}".format( + self.index, + Truncator(strip_tags(self.richtext)).words(10, truncate=" ...") + ) + # TODO Convert to Template def render(self, html_tag=None): template = """