dnscms: add sponsors page
This commit is contained in:
@@ -36,6 +36,7 @@ INSTALLED_APPS = [
|
||||
"venues",
|
||||
"news",
|
||||
"openinghours",
|
||||
"sponsors",
|
||||
# end cms apps
|
||||
"grapple",
|
||||
"graphene_django",
|
||||
@@ -200,6 +201,7 @@ GRAPPLE = {
|
||||
"venues",
|
||||
"news",
|
||||
"openinghours",
|
||||
"sponsors",
|
||||
],
|
||||
"EXPOSE_GRAPHIQL": True,
|
||||
}
|
||||
|
0
dnscms/sponsors/__init__.py
Normal file
0
dnscms/sponsors/__init__.py
Normal file
6
dnscms/sponsors/apps.py
Normal file
6
dnscms/sponsors/apps.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class SponsorsConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'sponsors'
|
30
dnscms/sponsors/migrations/0001_initial.py
Normal file
30
dnscms/sponsors/migrations/0001_initial.py
Normal file
@@ -0,0 +1,30 @@
|
||||
# Generated by Django 5.1 on 2025-07-23 08:42
|
||||
|
||||
import django.db.models.deletion
|
||||
import wagtail.fields
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
('wagtailcore', '0094_alter_page_locale'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='SponsorsPage',
|
||||
fields=[
|
||||
('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.page')),
|
||||
('lead', wagtail.fields.RichTextField(blank=True)),
|
||||
('sponsors', wagtail.fields.StreamField([('sponsor', 4)], blank=True, block_lookup={0: ('wagtail.blocks.CharBlock', (), {'label': 'Navn', 'max_length': 255}), 1: ('wagtail.images.blocks.ImageChooserBlock', (), {'label': 'Logo', 'required': False}), 2: ('wagtail.blocks.URLBlock', (), {'label': 'Nettside', 'required': False}), 3: ('wagtail.blocks.RichTextBlock', (), {'features': ['bold', 'italic', 'link', 'ul', 'ol'], 'label': 'Beskrivelse', 'required': False}), 4: ('wagtail.blocks.StructBlock', [[('name', 0), ('logo', 1), ('website', 2), ('text', 3)]], {})})),
|
||||
('body', wagtail.fields.StreamField([('paragraph', 0), ('image', 4), ('image_slider', 8), ('horizontal_rule', 10), ('featured', 18), ('page_section_navigation', 19), ('accordion', 23), ('fact_box', 26), ('embed', 27), ('raw_html', 28)], block_lookup={0: ('wagtail.blocks.RichTextBlock', (), {'label': 'Rik tekst'}), 1: ('wagtail.images.blocks.ImageChooserBlock', (), {'label': 'Bilde'}), 2: ('wagtail.blocks.ChoiceBlock', [], {'choices': [('fullwidth', 'Fullbredde'), ('bleed', 'Utfallende'), ('original', 'Uendret størrelse')], 'icon': 'cup', 'label': 'Bildeformat'}), 3: ('wagtail.blocks.CharBlock', (), {'label': 'Bildetekst', 'max_length': 512, 'required': False}), 4: ('wagtail.blocks.StructBlock', [[('image', 1), ('image_format', 2), ('text', 3)]], {}), 5: ('wagtail.blocks.CharBlock', (), {'label': 'Tekst', 'max_length': 512, 'required': False}), 6: ('wagtail.blocks.StructBlock', [[('image', 1), ('text', 5)]], {}), 7: ('wagtail.blocks.ListBlock', (6,), {'label': 'Bilder', 'min_num': 1}), 8: ('wagtail.blocks.StructBlock', [[('images', 7)]], {}), 9: ('wagtail.blocks.ChoiceBlock', [], {'choices': [('deepBrick', 'Dyp tegl'), ('neufPink', 'Griserosa'), ('goldenOrange', 'Gyllen oransje'), ('goldenBeige', 'Gyllen beige'), ('chateauBlue', 'Slottsblå')], 'label': 'Farge', 'required': False}), 10: ('wagtail.blocks.StructBlock', [[('color', 9)]], {}), 11: ('wagtail.blocks.CharBlock', (), {'label': 'Tittel', 'max_length': 64, 'required': True}), 12: ('wagtail.blocks.RichTextBlock', (), {'features': ['bold', 'italic', 'link'], 'label': 'Tekst', 'required': True}), 13: ('wagtail.blocks.PageChooserBlock', (), {'header': 'Fremhevet side', 'required': True}), 14: ('wagtail.blocks.CharBlock', (), {'default': 'Les mer', 'help_text': 'Lenketeksten som tar deg videre til siden. Tips: Ikke start med "Trykk her"', 'label': 'Lenketekst', 'max_length': 64, 'required': True}), 15: ('wagtail.blocks.ChoiceBlock', [], {'choices': [('betongGray', 'Betonggrå'), ('deepBrick', 'Dyp tegl'), ('neufPink', 'Griserosa'), ('goldenOrange', 'Gyllen oransje'), ('goldenBeige', 'Gyllen beige'), ('chateauBlue', 'Slottsblå')], 'label': 'Bakgrunnsfarge'}), 16: ('wagtail.blocks.ChoiceBlock', [], {'choices': [('left', 'Venstre'), ('right', 'Høyre')], 'label': 'Bildeplassering'}), 17: ('wagtail.images.blocks.ImageChooserBlock', (), {'header': 'Overstyr bilde', 'help_text': 'Bildet som er tilknyttet undersiden du vil fremheve, vil automatisk brukes. Om det mangler eller du vil overstyre hvilket bilde som et brukes, kan du velge et her.', 'required': False}), 18: ('wagtail.blocks.StructBlock', [[('title', 11), ('text', 12), ('featured_page', 13), ('link_text', 14), ('background_color', 15), ('image_position', 16), ('featured_image_override', 17)]], {}), 19: ('dnscms.blocks.PageSectionNavigationBlock', (), {}), 20: ('wagtail.blocks.CharBlock', (), {'label': 'Overskrift', 'max_length': 64, 'required': True}), 21: ('wagtail.blocks.StructBlock', [[('image', 1), ('image_format', 2), ('text', 3)]], {'label': 'Bilde'}), 22: ('wagtail.blocks.StreamBlock', [[('paragraph', 0), ('image', 21)]], {}), 23: ('wagtail.blocks.StructBlock', [[('heading', 20), ('body', 22)]], {}), 24: ('wagtail.blocks.ChoiceBlock', [], {'choices': [('betongGray', 'Betonggrå'), ('deepBrick', 'Dyp tegl'), ('neufPink', 'Griserosa'), ('goldenOrange', 'Gyllen oransje'), ('goldenBeige', 'Gyllen beige'), ('chateauBlue', 'Slottsblå')], 'label': 'Bakgrunnsfarge', 'required': False}), 25: ('wagtail.blocks.RichTextBlock', (), {'features': ['bold', 'italic', 'link', 'ol', 'ul', 'h2', 'h3'], 'label': 'Innhold'}), 26: ('wagtail.blocks.StructBlock', [[('background_color', 24), ('body', 25)]], {}), 27: ('wagtail.embeds.blocks.EmbedBlock', (), {}), 28: ('wagtail.blocks.RawHTMLBlock', (), {})})),
|
||||
],
|
||||
options={
|
||||
'abstract': False,
|
||||
},
|
||||
bases=('wagtailcore.page',),
|
||||
),
|
||||
]
|
0
dnscms/sponsors/migrations/__init__.py
Normal file
0
dnscms/sponsors/migrations/__init__.py
Normal file
62
dnscms/sponsors/models.py
Normal file
62
dnscms/sponsors/models.py
Normal file
@@ -0,0 +1,62 @@
|
||||
from grapple.helpers import register_singular_query_field, register_streamfield_block
|
||||
from grapple.models import GraphQLImage, GraphQLRichText, GraphQLStreamfield, GraphQLString
|
||||
from wagtail import blocks
|
||||
from wagtail.admin.panels import (
|
||||
FieldPanel,
|
||||
)
|
||||
from wagtail.fields import RichTextField, StreamField
|
||||
from wagtail.images.blocks import ImageChooserBlock
|
||||
from wagtail.models import Page
|
||||
from wagtail.search import index
|
||||
|
||||
from dnscms.blocks import BASE_BLOCKS
|
||||
|
||||
|
||||
@register_streamfield_block
|
||||
class SponsorBlock(blocks.StructBlock):
|
||||
name = blocks.CharBlock(max_length=255, label="Navn")
|
||||
logo = ImageChooserBlock(required=False, label="Logo")
|
||||
website = blocks.URLBlock(required=False, label="Nettside")
|
||||
text = blocks.RichTextBlock(
|
||||
features=["bold", "italic", "link", "ul", "ol"], required=False, label="Beskrivelse"
|
||||
)
|
||||
|
||||
graphql_fields = [
|
||||
GraphQLString("name", required=False),
|
||||
GraphQLImage("logo", required=False),
|
||||
GraphQLString("website", required=False),
|
||||
GraphQLString("text", required=False),
|
||||
]
|
||||
|
||||
class Meta:
|
||||
label = "Sponsor"
|
||||
icon = "tag"
|
||||
|
||||
|
||||
@register_singular_query_field("sponsorsPage")
|
||||
class SponsorsPage(Page):
|
||||
max_count = 1
|
||||
subpage_types = []
|
||||
|
||||
lead = RichTextField(features=["italic", "link"], blank=True)
|
||||
sponsors = StreamField(
|
||||
[
|
||||
("sponsor", SponsorBlock()),
|
||||
],
|
||||
blank=True,
|
||||
)
|
||||
body = StreamField(BASE_BLOCKS)
|
||||
|
||||
content_panels = Page.content_panels + [
|
||||
FieldPanel("lead", heading="Ingress"),
|
||||
FieldPanel("body", heading="Innhold"),
|
||||
FieldPanel("sponsors", heading="Sponsorer"),
|
||||
]
|
||||
|
||||
graphql_fields = [
|
||||
GraphQLRichText("lead"),
|
||||
GraphQLStreamfield("body"),
|
||||
GraphQLStreamfield("sponsors"),
|
||||
]
|
||||
|
||||
search_fields = Page.search_fields + [index.SearchField("body"), index.SearchField("sponsors")]
|
Reference in New Issue
Block a user