add pigs to event categories, fallback to those
This commit is contained in:
@ -0,0 +1,23 @@
|
|||||||
|
# Generated by Django 5.0.6 on 2024-06-06 00:20
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('events', '0029_eventpage_free'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='eventcategory',
|
||||||
|
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='Standardgris for arrangementer av denne typen.', max_length=32),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='eventpage',
|
||||||
|
name='pig',
|
||||||
|
field=models.CharField(blank=True, choices=[('', 'Ingen'), ('automatic', 'Automatisk'), ('logo', 'Logogrisen'), ('music', 'Musikergrisen'), ('drink', 'Drikkegrisen'), ('dance', 'Dansegrisen'), ('point', 'Pekegrisen'), ('student', 'Studentgrisen'), ('listen', 'Lyttegrisen'), ('guard', 'Vaktgrisen'), ('key', 'Nøkkelgrisen'), ('chill', 'Liggegrisen'), ('peek', 'Tittegrisen')], default='automatic', help_text='Grisen som henger på arrangementssiden. Automatisk fører til at en velges basert på arrangementets kategori.', max_length=32),
|
||||||
|
),
|
||||||
|
]
|
@ -30,6 +30,20 @@ from wagtail.snippets.models import register_snippet
|
|||||||
from dnscms.fields import CommonStreamField
|
from dnscms.fields import CommonStreamField
|
||||||
from venues.models import VenuePage
|
from venues.models import VenuePage
|
||||||
|
|
||||||
|
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"),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
@register_singular_query_field("eventIndex")
|
@register_singular_query_field("eventIndex")
|
||||||
class EventIndex(Page):
|
class EventIndex(Page):
|
||||||
@ -68,12 +82,30 @@ class EventCategory(models.Model):
|
|||||||
default=False, help_text="Skal denne kategorien være mulig å filtrere på i programmet?"
|
default=False, help_text="Skal denne kategorien være mulig å filtrere på i programmet?"
|
||||||
)
|
)
|
||||||
|
|
||||||
panels = [TitleFieldPanel("name"), FieldPanel("slug"), FieldPanel("show_in_filters")]
|
PIG_CHOICES = [
|
||||||
|
("", "Ingen"),
|
||||||
|
] + ALL_PIGS
|
||||||
|
|
||||||
|
pig = models.CharField(
|
||||||
|
max_length=32,
|
||||||
|
choices=PIG_CHOICES,
|
||||||
|
default="",
|
||||||
|
blank=True,
|
||||||
|
help_text="Standardgris for arrangementer av denne typen.",
|
||||||
|
)
|
||||||
|
|
||||||
|
panels = [
|
||||||
|
TitleFieldPanel("name"),
|
||||||
|
FieldPanel("slug"),
|
||||||
|
FieldPanel("show_in_filters"),
|
||||||
|
FieldPanel("pig", heading="Gris"),
|
||||||
|
]
|
||||||
|
|
||||||
graphql_fields = [
|
graphql_fields = [
|
||||||
GraphQLString("name", required=True),
|
GraphQLString("name", required=True),
|
||||||
GraphQLString("slug", required=True),
|
GraphQLString("slug", required=True),
|
||||||
GraphQLBoolean("show_in_filters", required=True),
|
GraphQLBoolean("show_in_filters", required=True),
|
||||||
|
GraphQLString("pig", required=True),
|
||||||
]
|
]
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
@ -166,20 +198,19 @@ class EventPage(Page):
|
|||||||
|
|
||||||
PIG_CHOICES = [
|
PIG_CHOICES = [
|
||||||
("", "Ingen"),
|
("", "Ingen"),
|
||||||
("logo", "Logogrisen"),
|
("automatic", "Automatisk"),
|
||||||
("music", "Musikergrisen"),
|
] + ALL_PIGS
|
||||||
("drink", "Drikkegrisen"),
|
|
||||||
("dance", "Dansegrisen"),
|
|
||||||
("point", "Pekegrisen"),
|
|
||||||
("student", "Studentgrisen"),
|
|
||||||
("listen", "Lyttegrisen"),
|
|
||||||
("guard", "Vaktgrisen"),
|
|
||||||
("key", "Nøkkelgrisen"),
|
|
||||||
("chill", "Liggegrisen"),
|
|
||||||
("peek", "Tittegrisen"),
|
|
||||||
]
|
|
||||||
|
|
||||||
pig = models.CharField(max_length=32, choices=PIG_CHOICES, default="", blank=True)
|
pig = models.CharField(
|
||||||
|
max_length=32,
|
||||||
|
choices=PIG_CHOICES,
|
||||||
|
default="automatic",
|
||||||
|
blank=True,
|
||||||
|
help_text=(
|
||||||
|
"Grisen som henger på arrangementssiden. "
|
||||||
|
"Automatisk fører til at en velges basert på arrangementets kategori."
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
ticket_url = models.URLField(
|
ticket_url = models.URLField(
|
||||||
blank=True,
|
blank=True,
|
||||||
@ -221,7 +252,7 @@ class EventPage(Page):
|
|||||||
FieldPanel("body"),
|
FieldPanel("body"),
|
||||||
FieldPanel("categories", widget=forms.CheckboxSelectMultiple),
|
FieldPanel("categories", widget=forms.CheckboxSelectMultiple),
|
||||||
FieldPanel("organizers", widget=forms.SelectMultiple),
|
FieldPanel("organizers", widget=forms.SelectMultiple),
|
||||||
FieldPanel("pig", heading="Bakgrunnsgris"),
|
FieldPanel("pig", heading="Gris"),
|
||||||
FieldPanel(
|
FieldPanel(
|
||||||
"facebook_url",
|
"facebook_url",
|
||||||
heading="Facebook-lenke",
|
heading="Facebook-lenke",
|
||||||
|
@ -6,6 +6,7 @@ import { EventHeader } from "@/components/events/EventHeader";
|
|||||||
import { BgPig } from "@/components/general/BgPig";
|
import { BgPig } from "@/components/general/BgPig";
|
||||||
import { graphql } from "@/gql";
|
import { graphql } from "@/gql";
|
||||||
import { EventFragment } from "@/gql/graphql";
|
import { EventFragment } from "@/gql/graphql";
|
||||||
|
import { getEventPig } from "@/lib/event";
|
||||||
import { notFound } from "next/navigation";
|
import { notFound } from "next/navigation";
|
||||||
|
|
||||||
export async function generateStaticParams() {
|
export async function generateStaticParams() {
|
||||||
@ -48,6 +49,7 @@ export default async function Page({ params }: { params: { slug: string } }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const event = (data?.event ?? {}) as EventFragment;
|
const event = (data?.event ?? {}) as EventFragment;
|
||||||
|
const eventPig = getEventPig(event);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@ -60,7 +62,7 @@ export default async function Page({ params }: { params: { slug: string } }) {
|
|||||||
<Blocks blocks={event.body} />
|
<Blocks blocks={event.body} />
|
||||||
</section>
|
</section>
|
||||||
</main>
|
</main>
|
||||||
{event.pig && <BgPig type={event.pig} color="white" />}
|
{eventPig && <BgPig type={eventPig} color="white" />}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ const documents = {
|
|||||||
"\n query home {\n events: eventIndex {\n ... on EventIndex {\n futureEvents {\n ... on EventPage {\n ...Event\n }\n }\n }\n }\n home: page(contentType: \"home.HomePage\", urlPath: \"/home/\") {\n ... on HomePage {\n ...Home\n }\n }\n news: pages(contentType: \"news.newsPage\", limit: 3) {\n ... on NewsPage {\n ...News\n }\n }\n }\n ": types.HomeDocument,
|
"\n query home {\n events: eventIndex {\n ... on EventIndex {\n futureEvents {\n ... on EventPage {\n ...Event\n }\n }\n }\n }\n home: page(contentType: \"home.HomePage\", urlPath: \"/home/\") {\n ... on HomePage {\n ...Home\n }\n }\n news: pages(contentType: \"news.newsPage\", limit: 3) {\n ... on NewsPage {\n ...News\n }\n }\n }\n ": types.HomeDocument,
|
||||||
"\n fragment Blocks on StreamFieldInterface {\n id\n blockType\n field\n ... on RichTextBlock {\n rawValue\n value\n }\n ... on ImageWithTextBlock {\n image {\n ...Image\n }\n imageFormat\n text\n }\n ... on ImageSliderBlock {\n images {\n ... on ImageSliderItemBlock {\n image {\n ...Image\n }\n text\n }\n }\n }\n ... on HorizontalRuleBlock {\n color\n }\n ... on FeaturedBlock {\n title\n featuredBlockText: text\n linkText\n imagePosition\n featuredPage {\n contentType\n pageType\n url\n ... on EventPage {\n featuredImage {\n ...Image\n }\n }\n ... on NewsPage {\n featuredImage {\n ...Image\n }\n }\n }\n featuredImageOverride {\n ...Image\n }\n }\n }\n": types.BlocksFragmentDoc,
|
"\n fragment Blocks on StreamFieldInterface {\n id\n blockType\n field\n ... on RichTextBlock {\n rawValue\n value\n }\n ... on ImageWithTextBlock {\n image {\n ...Image\n }\n imageFormat\n text\n }\n ... on ImageSliderBlock {\n images {\n ... on ImageSliderItemBlock {\n image {\n ...Image\n }\n text\n }\n }\n }\n ... on HorizontalRuleBlock {\n color\n }\n ... on FeaturedBlock {\n title\n featuredBlockText: text\n linkText\n imagePosition\n featuredPage {\n contentType\n pageType\n url\n ... on EventPage {\n featuredImage {\n ...Image\n }\n }\n ... on NewsPage {\n featuredImage {\n ...Image\n }\n }\n }\n featuredImageOverride {\n ...Image\n }\n }\n }\n": types.BlocksFragmentDoc,
|
||||||
"\n fragment Image on CustomImage {\n id\n url\n width\n height\n alt\n attribution\n }\n": types.ImageFragmentDoc,
|
"\n fragment Image on CustomImage {\n id\n url\n width\n height\n alt\n attribution\n }\n": types.ImageFragmentDoc,
|
||||||
"\n fragment Event on EventPage {\n __typename\n id\n slug\n title\n body {\n id\n blockType\n field\n ... on RichTextBlock {\n rawValue\n value\n }\n }\n featuredImage {\n ...Image\n }\n pig\n facebookUrl\n ticketUrl\n free\n priceRegular\n priceMember\n priceStudent\n categories {\n ... on EventCategory {\n name\n slug\n }\n }\n occurrences {\n ... on EventOccurrence {\n __typename\n id\n start\n end\n venue {\n __typename\n id\n slug\n title\n preposition\n url\n }\n }\n }\n }\n": types.EventFragmentDoc,
|
"\n fragment Event on EventPage {\n __typename\n id\n slug\n title\n body {\n id\n blockType\n field\n ... on RichTextBlock {\n rawValue\n value\n }\n }\n featuredImage {\n ...Image\n }\n pig\n facebookUrl\n ticketUrl\n free\n priceRegular\n priceMember\n priceStudent\n categories {\n ... on EventCategory {\n name\n slug\n pig\n }\n }\n occurrences {\n ... on EventOccurrence {\n __typename\n id\n start\n end\n venue {\n __typename\n id\n slug\n title\n preposition\n url\n }\n }\n }\n }\n": types.EventFragmentDoc,
|
||||||
"\n query futureEvents {\n events: eventIndex {\n ... on EventIndex {\n futureEvents {\n ... on EventPage {\n ...Event\n }\n }\n }\n }\n eventCategories: eventCategories {\n ... on EventCategory {\n name\n slug\n showInFilters\n }\n }\n }\n": types.FutureEventsDocument,
|
"\n query futureEvents {\n events: eventIndex {\n ... on EventIndex {\n futureEvents {\n ... on EventPage {\n ...Event\n }\n }\n }\n }\n eventCategories: eventCategories {\n ... on EventCategory {\n name\n slug\n showInFilters\n }\n }\n }\n": types.FutureEventsDocument,
|
||||||
"\n fragment News on NewsPage {\n __typename\n id\n slug\n title\n firstPublishedAt\n excerpt\n featuredImage {\n ...Image\n }\n body {\n ...Blocks\n }\n }\n": types.NewsFragmentDoc,
|
"\n fragment News on NewsPage {\n __typename\n id\n slug\n title\n firstPublishedAt\n excerpt\n featuredImage {\n ...Image\n }\n body {\n ...Blocks\n }\n }\n": types.NewsFragmentDoc,
|
||||||
"\n fragment NewsIndex on NewsIndex {\n __typename\n id\n slug\n title\n lead\n }\n": types.NewsIndexFragmentDoc,
|
"\n fragment NewsIndex on NewsIndex {\n __typename\n id\n slug\n title\n lead\n }\n": types.NewsIndexFragmentDoc,
|
||||||
@ -137,7 +137,7 @@ export function graphql(source: "\n fragment Image on CustomImage {\n id\n
|
|||||||
/**
|
/**
|
||||||
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
|
* 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 Event on EventPage {\n __typename\n id\n slug\n title\n body {\n id\n blockType\n field\n ... on RichTextBlock {\n rawValue\n value\n }\n }\n featuredImage {\n ...Image\n }\n pig\n facebookUrl\n ticketUrl\n free\n priceRegular\n priceMember\n priceStudent\n categories {\n ... on EventCategory {\n name\n slug\n }\n }\n occurrences {\n ... on EventOccurrence {\n __typename\n id\n start\n end\n venue {\n __typename\n id\n slug\n title\n preposition\n url\n }\n }\n }\n }\n"): (typeof documents)["\n fragment Event on EventPage {\n __typename\n id\n slug\n title\n body {\n id\n blockType\n field\n ... on RichTextBlock {\n rawValue\n value\n }\n }\n featuredImage {\n ...Image\n }\n pig\n facebookUrl\n ticketUrl\n free\n priceRegular\n priceMember\n priceStudent\n categories {\n ... on EventCategory {\n name\n slug\n }\n }\n occurrences {\n ... on EventOccurrence {\n __typename\n id\n start\n end\n venue {\n __typename\n id\n slug\n title\n preposition\n url\n }\n }\n }\n }\n"];
|
export function graphql(source: "\n fragment Event on EventPage {\n __typename\n id\n slug\n title\n body {\n id\n blockType\n field\n ... on RichTextBlock {\n rawValue\n value\n }\n }\n featuredImage {\n ...Image\n }\n pig\n facebookUrl\n ticketUrl\n free\n priceRegular\n priceMember\n priceStudent\n categories {\n ... on EventCategory {\n name\n slug\n pig\n }\n }\n occurrences {\n ... on EventOccurrence {\n __typename\n id\n start\n end\n venue {\n __typename\n id\n slug\n title\n preposition\n url\n }\n }\n }\n }\n"): (typeof documents)["\n fragment Event on EventPage {\n __typename\n id\n slug\n title\n body {\n id\n blockType\n field\n ... on RichTextBlock {\n rawValue\n value\n }\n }\n featuredImage {\n ...Image\n }\n pig\n facebookUrl\n ticketUrl\n free\n priceRegular\n priceMember\n priceStudent\n categories {\n ... on EventCategory {\n name\n slug\n pig\n }\n }\n occurrences {\n ... on EventOccurrence {\n __typename\n id\n start\n end\n venue {\n __typename\n id\n slug\n title\n preposition\n url\n }\n }\n }\n }\n"];
|
||||||
/**
|
/**
|
||||||
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
|
* 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
@ -27,6 +27,12 @@ export const PIG_NAMES = [
|
|||||||
"peek",
|
"peek",
|
||||||
];
|
];
|
||||||
|
|
||||||
|
export function randomElement(array: any[]): any | undefined {
|
||||||
|
return array.length
|
||||||
|
? array[Math.floor(Math.random() * array.length)]
|
||||||
|
: undefined;
|
||||||
|
}
|
||||||
|
|
||||||
const BlockFragmentDefinition = graphql(`
|
const BlockFragmentDefinition = graphql(`
|
||||||
fragment Blocks on StreamFieldInterface {
|
fragment Blocks on StreamFieldInterface {
|
||||||
id
|
id
|
||||||
|
@ -11,6 +11,7 @@ import {
|
|||||||
import { toLocalTime, formatDate } from "./date";
|
import { toLocalTime, formatDate } from "./date";
|
||||||
import { graphql } from "@/gql";
|
import { graphql } from "@/gql";
|
||||||
import { EventFragment, EventCategory, EventOccurrence } from "@/gql/graphql";
|
import { EventFragment, EventCategory, EventOccurrence } from "@/gql/graphql";
|
||||||
|
import { PIG_NAMES, PigName, randomElement } from "@/lib/common";
|
||||||
|
|
||||||
export type {
|
export type {
|
||||||
EventFragment,
|
EventFragment,
|
||||||
@ -51,6 +52,7 @@ const EventFragmentDefinition = graphql(`
|
|||||||
... on EventCategory {
|
... on EventCategory {
|
||||||
name
|
name
|
||||||
slug
|
slug
|
||||||
|
pig
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
occurrences {
|
occurrences {
|
||||||
@ -181,3 +183,20 @@ export function getClosestOccurrence(event: EventFragment) {
|
|||||||
|
|
||||||
return futureOccurrences[0];
|
return futureOccurrences[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getEventPig(event: EventFragment): string | null {
|
||||||
|
if (event.pig === "" || typeof event.pig !== "string") {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (PIG_NAMES.includes(event.pig)) {
|
||||||
|
return event.pig;
|
||||||
|
}
|
||||||
|
if (event.pig === "automatic") {
|
||||||
|
const categoryPigs = event.categories
|
||||||
|
?.map((category) => category.pig)
|
||||||
|
.filter((pig) => PIG_NAMES.includes(pig));
|
||||||
|
const chosenPig = randomElement(categoryPigs ?? []);
|
||||||
|
return typeof chosenPig === "string" ? chosenPig : null;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user