Files
neuf-www/dnscms/venues/models.py

197 lines
6.8 KiB
Python

from django.db import models
from grapple.helpers import register_singular_query_field
from grapple.models import (
GraphQLBoolean,
GraphQLImage,
GraphQLRichText,
GraphQLStreamfield,
GraphQLString,
)
from wagtail.admin.panels import FieldPanel, FieldRowPanel, MultiFieldPanel
from wagtail.fields import RichTextField
from wagtail.models import Page
from wagtail.search import index
from wagtail_wordpress_import.models import WPImportedPageMixin
from dnscms.fields import CommonStreamField
@register_singular_query_field("venueIndex")
class VenueIndex(Page):
# there can only be one venue index page
max_count = 1
subpage_types = ["venues.VenuePage"]
lead = RichTextField(features=["bold", "italic", "link"], blank=True)
body = CommonStreamField
content_panels = Page.content_panels + [
FieldPanel("lead", heading="Ingress"),
FieldPanel("body", heading="Innhold"),
]
graphql_fields = [GraphQLRichText("lead"), GraphQLStreamfield("body")]
@register_singular_query_field("venueRentalIndex")
class VenueRentalIndex(Page):
# there can only be one venue index page
max_count = 1
subpage_types = []
lead = RichTextField(features=["bold", "italic", "link"], blank=True)
body = CommonStreamField
content_panels = Page.content_panels + [
FieldPanel("lead", heading="Ingress"),
FieldPanel("body", heading="Innhold"),
]
graphql_fields = [GraphQLRichText("lead"), GraphQLStreamfield("body")]
class VenuePage(WPImportedPageMixin, Page):
# no children
subpage_types = []
parent_page_types = ["venues.VenueIndex"]
# should not be able to be shown in menus
show_in_menus = False
featured_image = models.ForeignKey(
"images.CustomImage",
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name="+",
help_text=("Bilde av lokalet"),
)
body = CommonStreamField
show_as_bookable = models.BooleanField(
default=True, help_text="Skal lokalet dukke i oversikten over lokaler som leies ut?"
)
floor = models.CharField(
blank=True,
max_length=255,
)
preposition = models.CharField(
blank=True, max_length=255, help_text="Er man i eller på lokalet?"
)
tech_specs_url = models.URLField(
blank=True,
max_length=512,
help_text="Lenke til tekniske spesifikasjoner for lokalet",
)
used_for = models.CharField(blank=True, max_length=255)
capability_audio = models.CharField(blank=True, max_length=255)
capability_audio_video = models.CharField(blank=True, max_length=255)
capability_bar = models.CharField(blank=True, max_length=255)
capability_lighting = models.CharField(blank=True, max_length=255)
capacity_legal = models.CharField(blank=True, max_length=255)
capacity_standing = models.CharField(blank=True, max_length=255)
capacity_sitting = models.CharField(blank=True, max_length=255)
# "used_for": "Konsert, foredrag, fest, debatt, teater",
capability_panels = [
FieldRowPanel(
children=[
FieldPanel("capability_bar", heading="Bar"),
FieldPanel("capability_audio", heading="Lyd"),
FieldPanel("capability_lighting", heading="Lys"),
FieldPanel("capability_audio_video", heading="A/V"),
],
),
]
capacity_panels = [
FieldRowPanel(
children=[
FieldPanel("capacity_legal", heading="Branntillatelse for"),
FieldPanel("capacity_sitting", heading="Stående"),
FieldPanel("capacity_standing", heading="Sittende"),
],
),
]
content_panels = Page.content_panels + [
FieldPanel("featured_image"),
FieldPanel("body"),
FieldPanel("floor", heading="Etasje"),
FieldPanel("preposition", heading="Preposisjon"),
FieldPanel("show_as_bookable", heading="Vis på utleieside"),
FieldPanel("used_for", heading="Egnet for"),
MultiFieldPanel(
heading="Kapabiliteter",
children=capability_panels,
),
MultiFieldPanel(
heading="Kapasitet",
children=capacity_panels,
),
FieldPanel("tech_specs_url", heading="Tekniske spesifikasjoner"),
]
graphql_fields = [
GraphQLImage("featured_image"),
GraphQLStreamfield("body"),
GraphQLString("floor"),
GraphQLString("preposition"),
GraphQLString("used_for"),
GraphQLString("tech_specs_url"),
GraphQLBoolean("show_as_bookable"),
GraphQLString("capability_audio"),
GraphQLString("capability_audio_video"),
GraphQLString("capability_bar"),
GraphQLString("capability_lighting"),
GraphQLString("capacity_legal"),
GraphQLString("capacity_standing"),
GraphQLString("capacity_sitting"),
]
search_fields = Page.search_fields + [
index.SearchField("body"),
]
settings_panels = Page.settings_panels + WPImportedPageMixin.wordpress_panels
def import_wordpress_data(self, data):
import html
# Wagtail page model fields
self.title = html.unescape(data["title"])
self.slug = data["slug"]
self.first_published_at = data["first_published_at"]
self.last_published_at = data["last_published_at"]
self.latest_revision_created_at = data["latest_revision_created_at"]
self.search_description = data["search_description"]
# debug fields
self.wp_post_id = data["wp_post_id"]
self.wp_post_type = data["wp_post_type"]
self.wp_link = data["wp_link"]
self.wp_raw_content = data["wp_raw_content"]
self.wp_block_json = data["wp_block_json"]
self.wp_processed_content = data["wp_processed_content"]
self.wp_normalized_styles = data["wp_normalized_styles"]
self.wp_post_meta = data["wp_post_meta"]
# own model fields
self.body = data["body"] or ""
meta = data["wp_post_meta"]
self.show_as_bookable = meta.get("neuf_venues_show_on_booking_page", False)
self.preposition = meta.get("neuf_venues_preposition") or ""
self.floor = meta.get("neuf_venues_floor") or ""
self.used_for = meta.get("neuf_venues_used_for") or ""
self.capability_bar = meta.get("neuf_venues_bar") or ""
self.capability_audio = meta.get("neuf_venues_audio") or ""
self.capability_lighting = meta.get("neuf_venues_lighting") or ""
self.capability_audio_video = meta.get("neuf_venues_audio_video") or ""
self.capacity_legal = meta.get("neuf_venues_capacity_legal") or ""
self.capacity_standing = meta.get("neuf_venues_capacity_standing") or ""
self.capacity_sitting = meta.get("neuf_venues_capacity_sitting") or ""