fix headline

This commit is contained in:
bkfox 2020-05-20 16:23:37 +02:00
parent 4153551fde
commit 4c7b363aea

View File

@ -6,6 +6,7 @@ from django.urls import reverse
from django.utils import timezone as tz from django.utils import timezone as tz
from django.utils.text import slugify from django.utils.text import slugify
from django.utils.html import format_html from django.utils.html import format_html
from django.utils.safestring import mark_safe
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from django.utils.functional import cached_property from django.utils.functional import cached_property
@ -99,6 +100,7 @@ class Page(models.Model):
return '{}'.format(self.title or self.pk) return '{}'.format(self.title or self.pk)
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
# TODO: bleach clean
if not self.slug: if not self.slug:
self.slug = slugify(self.title)[:100] self.slug = slugify(self.title)[:100]
count = Page.objects.filter(slug__startswith=self.slug).count() count = Page.objects.filter(slug__startswith=self.slug).count()
@ -133,9 +135,9 @@ class Page(models.Model):
def headline(self): def headline(self):
if not self.content: if not self.content:
return '' return ''
content = bleach.clean(self.content) content = bleach.clean(self.content, strip=True)
headline = headline_re.search(content) headline = headline_re.search(content)
return headline.groupdict()['headline'] if headline else '' return mark_safe(headline.groupdict()['headline']) if headline else ''
@classmethod @classmethod
def get_init_kwargs_from(cls, page, **kwargs): def get_init_kwargs_from(cls, page, **kwargs):