dnscms: improve news app

This commit is contained in:
2026-05-19 22:00:11 +02:00
parent 29c61ffc76
commit 447e1bd3ff
8 changed files with 164 additions and 41 deletions
+22 -8
View File
@@ -1,4 +1,5 @@
from django.db import models
from django.utils.translation import gettext_lazy as _
from grapple.helpers import register_singular_query_field
from grapple.models import GraphQLImage, GraphQLRichText, GraphQLStreamfield, GraphQLString
from wagtail.admin.panels import FieldPanel
@@ -19,7 +20,7 @@ class NewsIndex(HeadlessMixin, Page):
lead = RichTextField(features=["italic", "link"], blank=True)
content_panels = Page.content_panels + [
FieldPanel("lead", heading="Ingress"),
FieldPanel("lead", heading=_("Lead")),
]
graphql_fields = [
@@ -28,6 +29,10 @@ class NewsIndex(HeadlessMixin, Page):
search_fields = []
class Meta:
verbose_name = _("news index")
verbose_name_plural = _("news indexes")
class NewsPage(HeadlessMixin, WPImportedPageMixin, Page):
subpage_types = []
@@ -43,23 +48,28 @@ class NewsPage(HeadlessMixin, WPImportedPageMixin, Page):
blank=True,
on_delete=models.SET_NULL,
related_name="+",
help_text=(
"Velg et bilde til bruk i på forsiden og andre visningsflater. "
"Bør være et bilde eller en illustrasjon uten tekst."
help_text=_(
"Choose an image for use on the front page and other surfaces. "
"Should be a photo or an illustration without too much text."
),
)
content_panels = Page.content_panels + [
FieldPanel(
"excerpt",
heading="Utdrag",
help_text="En veldig kort oppsummering av innholdet i artikkelen. Brukes på forsiden og i artikkeloversikten.",
heading=_("Excerpt"),
help_text=_(
"A very short summary of the article's content. "
"Used on the front page and in the article listing."
),
),
FieldPanel("featured_image"),
FieldPanel(
"lead",
heading="Ingress",
help_text="Et kortfattet, innledende avsnitt som oppsummerer hovedinnholdet i artikkelen.",
heading=_("Lead"),
help_text=_(
"A brief, introductory paragraph that summarizes the main content of the article."
),
),
FieldPanel("body"),
]
@@ -77,6 +87,10 @@ class NewsPage(HeadlessMixin, WPImportedPageMixin, Page):
index.SearchField("body"),
]
class Meta:
verbose_name = _("news article")
verbose_name_plural = _("news articles")
def import_wordpress_data(self, data):
import html