allow generic pages to have pigs

This commit is contained in:
2024-08-09 20:08:12 +02:00
parent 3d3d991fa7
commit 9d78cf2822
6 changed files with 63 additions and 10 deletions

13
dnscms/dnscms/options.py Normal file
View File

@ -0,0 +1,13 @@
ALL_PIGS = [
("logo", "Logogrisen"),
("music", "Musikergrisen"),
("drink", "Drikkegrisen"),
("dance", "Dansegrisen"),
("point", "Pekegrisen"),
("student", "Studentgrisen"),
("listen", "Lyttegrisen"),
("guard", "Vaktgrisen"),
("key", "Nøkkelgrisen"),
("chill", "Liggegrisen"),
("peek", "Tittegrisen"),
]

View File

@ -0,0 +1,18 @@
# Generated by Django 5.0.7 on 2024-08-09 18:04
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('generic', '0024_alter_genericpage_body'),
]
operations = [
migrations.AddField(
model_name='genericpage',
name='pig',
field=models.CharField(blank=True, choices=[('', 'Ingen'), ('logo', 'Logogrisen'), ('music', 'Musikergrisen'), ('drink', 'Drikkegrisen'), ('dance', 'Dansegrisen'), ('point', 'Pekegrisen'), ('student', 'Studentgrisen'), ('listen', 'Lyttegrisen'), ('guard', 'Vaktgrisen'), ('key', 'Nøkkelgrisen'), ('chill', 'Liggegrisen'), ('peek', 'Tittegrisen')], default='', help_text='Grisen nedi hjørnet.', max_length=32),
),
]

View File

@ -1,4 +1,5 @@
from grapple.models import GraphQLRichText, GraphQLStreamfield
from django.db import models
from grapple.models import GraphQLRichText, GraphQLStreamfield, GraphQLString
from wagtail.admin.panels import FieldPanel
from wagtail.fields import RichTextField, StreamField
from wagtail.models import Page
@ -6,6 +7,7 @@ from wagtail.search import index
from dnscms.blocks import PageSectionBlock
from dnscms.fields import BASE_BLOCKS
from dnscms.options import ALL_PIGS
class GenericPage(Page):
@ -15,14 +17,28 @@ class GenericPage(Page):
lead = RichTextField(features=["link"])
body = StreamField(BASE_BLOCKS + [("page_section", PageSectionBlock())])
PIG_CHOICES = [
("", "Ingen"),
] + ALL_PIGS
pig = models.CharField(
max_length=32,
choices=PIG_CHOICES,
default="",
blank=True,
help_text="Grisen nedi hjørnet.",
)
content_panels = Page.content_panels + [
FieldPanel("lead", heading="Ingress"),
FieldPanel("body", heading="Innhold"),
FieldPanel("pig", heading="Gris"),
]
graphql_fields = [
GraphQLRichText("lead"),
GraphQLStreamfield("body"),
GraphQLString("pig", required=True),
]
search_fields = Page.search_fields + [index.SearchField("lead"), index.SearchField("body")]

View File

@ -4,6 +4,7 @@ import { getClient } from "@/app/client";
import { notFound } from "next/navigation";
import { PageHeader } from "@/components/general/PageHeader";
import { PageContent } from "@/components/general/PageContent";
import { BgPig } from "@/components/general/BgPig";
export const dynamicParams = false;
@ -14,6 +15,7 @@ const GenericFragmentDefinition = graphql(`
urlPath
title
lead
pig
body {
...Blocks
}
@ -74,9 +76,12 @@ export default async function Page({ params }: { params: { url: string[] } }) {
}
return (
<>
<main className="site-main" id="main">
<PageHeader heading={page.title} lead={page.lead} />
<PageContent blocks={page.body} />
</main>
{page.pig && <BgPig type={page.pig} color="white" />}
</>
);
}

View File

@ -13,7 +13,7 @@ import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/
* Therefore it is highly recommended to use the babel or swc plugin for production.
*/
const documents = {
"\n fragment Generic on GenericPage {\n __typename\n id\n urlPath\n title\n lead\n body {\n ...Blocks\n }\n }\n": types.GenericFragmentDoc,
"\n fragment Generic on GenericPage {\n __typename\n id\n urlPath\n title\n lead\n pig\n body {\n ...Blocks\n }\n }\n": types.GenericFragmentDoc,
"\n query allGenericSlugs {\n pages(contentType: \"generic.GenericPage\") {\n id\n urlPath\n }\n }\n ": types.AllGenericSlugsDocument,
"\n query genericPageByUrl($urlPath: String!) {\n page: page(contentType: \"generic.GenericPage\", urlPath: $urlPath) {\n ... on GenericPage {\n ...Generic\n }\n }\n }\n ": types.GenericPageByUrlDocument,
"\n query allNewsSlugs {\n pages(contentType: \"news.NewsPage\") {\n id\n slug\n }\n }\n ": types.AllNewsSlugsDocument,
@ -69,7 +69,7 @@ export function graphql(source: string): unknown;
/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
export function graphql(source: "\n fragment Generic on GenericPage {\n __typename\n id\n urlPath\n title\n lead\n body {\n ...Blocks\n }\n }\n"): (typeof documents)["\n fragment Generic on GenericPage {\n __typename\n id\n urlPath\n title\n lead\n body {\n ...Blocks\n }\n }\n"];
export function graphql(source: "\n fragment Generic on GenericPage {\n __typename\n id\n urlPath\n title\n lead\n pig\n body {\n ...Blocks\n }\n }\n"): (typeof documents)["\n fragment Generic on GenericPage {\n __typename\n id\n urlPath\n title\n lead\n pig\n body {\n ...Blocks\n }\n }\n"];
/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/

File diff suppressed because one or more lines are too long