Skip to content
Snippets Groups Projects
Commit 05e83cb6 authored by Tomáš Valenta's avatar Tomáš Valenta
Browse files

page chooser blocks, max lengths, multi field panels, universal pages

parent c671d721
Branches
No related tags found
No related merge requests found
...@@ -5,6 +5,7 @@ from wagtail.blocks import ( ...@@ -5,6 +5,7 @@ from wagtail.blocks import (
StructBlock, StructBlock,
TextBlock, TextBlock,
URLBlock, URLBlock,
PageChooserBlock,
) )
from wagtail.documents.blocks import DocumentChooserBlock from wagtail.documents.blocks import DocumentChooserBlock
...@@ -15,7 +16,7 @@ class PersonBlock(StructBlock): ...@@ -15,7 +16,7 @@ class PersonBlock(StructBlock):
email = EmailBlock(label="E-mailová adresa", required=False) email = EmailBlock(label="E-mailová adresa", required=False)
class Meta: class Meta:
label = "Člověk" label = "Osoba"
template = "home/blocks/person_block.html" template = "home/blocks/person_block.html"
icon = "user" icon = "user"
...@@ -23,7 +24,7 @@ class PersonBlock(StructBlock): ...@@ -23,7 +24,7 @@ class PersonBlock(StructBlock):
class DocumentBlock(StructBlock): class DocumentBlock(StructBlock):
name = CharBlock(label="Jméno") name = CharBlock(label="Jméno")
date_added = DateBlock(label="Datum přidání", required=False) date_added = DateBlock(label="Datum přidání", required=False)
url = URLBlock(label="URL (místo dokumentu)", required=False) page = PageChooserBlock(label="Stránka (místo dokumentu)", required=False)
file = DocumentChooserBlock(label="Dokument", required=False) file = DocumentChooserBlock(label="Dokument", required=False)
class Meta: class Meta:
...@@ -34,7 +35,7 @@ class DocumentBlock(StructBlock): ...@@ -34,7 +35,7 @@ class DocumentBlock(StructBlock):
class EventBlock(StructBlock): class EventBlock(StructBlock):
name = CharBlock(label="Jméno") name = CharBlock(label="Jméno")
url = URLBlock(label="URL") page = PageChooserBlock(label="Stránka")
date = DateBlock(label="Datum konání", required=False) date = DateBlock(label="Datum konání", required=False)
location = CharBlock(label="Lokace", required=False) location = CharBlock(label="Lokace", required=False)
......
from django.db import models from django.db import models
from django.utils import timezone from django.utils import timezone
from wagtail.admin.panels import FieldPanel from wagtail.admin.panels import FieldPanel, MultiFieldPanel
from wagtail.fields import RichTextField, StreamField from wagtail.fields import RichTextField, StreamField
from wagtail.models import Page from wagtail.models import Page
...@@ -36,10 +36,10 @@ class HomePage(Page): ...@@ -36,10 +36,10 @@ class HomePage(Page):
# --- Contact info --- # --- Contact info ---
address = models.CharField(verbose_name="Sídlo") address = models.CharField(verbose_name="Sídlo", max_length=128)
branch = models.CharField(verbose_name="Pobočka") branch = models.CharField(verbose_name="Pobočka", max_length=128)
email = models.EmailField(verbose_name="Email") email = models.EmailField(verbose_name="Email", max_length=128)
ds_id = models.CharField(verbose_name="Datová schránka") ds_id = models.CharField(verbose_name="Datová schránka", max_length=128)
# --- People --- # --- People ---
...@@ -84,7 +84,8 @@ class HomePage(Page): ...@@ -84,7 +84,8 @@ class HomePage(Page):
) )
subpage_types = [ subpage_types = [
"home.HomeArticlesPage" "home.HomeArticlesPage",
"home.HomeUniversalPage",
] ]
content_panels = Page.content_panels + [ content_panels = Page.content_panels + [
...@@ -92,15 +93,25 @@ class HomePage(Page): ...@@ -92,15 +93,25 @@ class HomePage(Page):
FieldPanel("events", icon="calendar-alt"), FieldPanel("events", icon="calendar-alt"),
FieldPanel("documents", icon="doc-full-inverse"), FieldPanel("documents", icon="doc-full-inverse"),
FieldPanel("donation_text", icon="pilcrow"), FieldPanel("donation_text", icon="pilcrow"),
FieldPanel("address", icon="home"), MultiFieldPanel(
FieldPanel("branch", icon="home"), [
FieldPanel("email", icon="pilcrow"), FieldPanel("address", icon="home"),
FieldPanel("ds_id", icon="mail"), FieldPanel("branch", icon="home"),
FieldPanel("director", icon="user"), FieldPanel("email", icon="pilcrow"),
FieldPanel("controller", icon="user"), FieldPanel("ds_id", icon="mail"),
FieldPanel("council_members", icon="group"), ],
FieldPanel("volunteers", icon="group"), heading="Kontaktní údaje"
FieldPanel("employees", icon="group"), ),
MultiFieldPanel(
[
FieldPanel("director", icon="user"),
FieldPanel("controller", icon="user"),
FieldPanel("council_members", icon="group"),
FieldPanel("volunteers", icon="group"),
FieldPanel("employees", icon="group"),
],
heading="Lidé"
)
] ]
@property @property
...@@ -122,6 +133,9 @@ class HomePage(Page): ...@@ -122,6 +133,9 @@ class HomePage(Page):
[:3] [:3]
) )
class Meta:
verbose_name = "Domovká stránka"
class HomeArticlesPage(Page): class HomeArticlesPage(Page):
content = RichTextField(verbose_name="Obsah", blank=True, null=True) content = RichTextField(verbose_name="Obsah", blank=True, null=True)
...@@ -146,14 +160,22 @@ class HomeArticlesPage(Page): ...@@ -146,14 +160,22 @@ class HomeArticlesPage(Page):
.all() .all()
) )
class Meta:
verbose_name = "Rozcestník článků"
class HomeArticlePage(Page):
class HomeContentPageMixin(Page):
tags = models.ManyToManyField( tags = models.ManyToManyField(
"Tag", "Tag",
verbose_name="Štítky" verbose_name="Štítky"
) )
author = models.CharField(verbose_name="Autor") author = models.CharField(
verbose_name="Autor",
max_length=128,
blank=True,
null=True,
)
date = models.DateField( date = models.DateField(
verbose_name="Datum vytvoření", verbose_name="Datum vytvoření",
...@@ -181,12 +203,25 @@ class HomeArticlePage(Page): ...@@ -181,12 +203,25 @@ class HomeArticlePage(Page):
return self.perex return self.perex
class Meta:
abstract = True
ordering = ["-date"]
class HomeArticlePage(HomeContentPageMixin):
class Meta:
ordering = ["-date"]
verbose_name = "Článek"
class HomeUniversalPage(HomeContentPageMixin):
class Meta: class Meta:
ordering = ["-date"] ordering = ["-date"]
verbose_name = "Univerzální stránka"
class Tag(models.Model): class Tag(models.Model):
name = models.CharField(verbose_name="Jméno") name = models.CharField(verbose_name="Jméno", max_length=32)
class Meta: class Meta:
verbose_name = "Štítek" verbose_name = "Štítek"
......
<li> <li>
<a <a
href="{% if self.url %}{{ self.url }}{% else %}{{ self.file.url }}{% endif %}" href="{% if self.page %}{{ self.page }}{% else %}{{ self.file.url }}{% endif %}"
target="_blank" target="_blank"
> >
<h3 class="font-serif leading-4"> <h3 class="font-serif leading-4">
......
<a href="{{ self.url }}" target="_blank"> <a href="{{ self.page }}" target="_blank">
<li class="flex flex-col"> <li class="flex flex-col">
{% if self.date or self.location %} {% if self.date or self.location %}
<small class="text-pii-cyan uppercase"> <small class="text-pii-cyan uppercase">
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
{% block content %} {% block content %}
<main class="flex flex-col items-center gap-10 pt-14"> <main class="flex flex-col items-center gap-10 pt-14">
<div class="container"> <div class="container">
<ul class="flex gap-4 lg:h-96 lg:flex-nowrap flex-wrap"> <ul class="flex gap-4 lg:h-96 flex-wrap">
{% for article in page.articles %} {% for article in page.articles %}
<li class="bg-pii-cyan text-white p-7 lg:w-80"> <li class="bg-pii-cyan text-white p-7 lg:w-80">
<a <a
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment