Skip to content
Snippets Groups Projects
Commit 56ee4c97 authored by jan.bednarik's avatar jan.bednarik
Browse files

uniweb: Calendr agenda block

parent 6c09c465
Branches
No related tags found
2 merge requests!408Uniweb kalendáře,!407uniweb calendar
Pipeline #5599 passed
...@@ -57,3 +57,11 @@ ALIGN_CSS = { ...@@ -57,3 +57,11 @@ ALIGN_CSS = {
ARTICLES_PER_LINE = 3 ARTICLES_PER_LINE = 3
ARTICLES_PER_PAGE = ARTICLES_PER_LINE * 4 ARTICLES_PER_PAGE = ARTICLES_PER_LINE * 4
FUTURE = "future"
PAST = "past"
CALENDAR_EVENTS_CHOICES = (
(FUTURE, "budoucí"),
(PAST, "proběhlé"),
)
This diff is collapsed.
This diff is collapsed.
...@@ -27,6 +27,7 @@ from wagtail.images.blocks import ImageChooserBlock ...@@ -27,6 +27,7 @@ from wagtail.images.blocks import ImageChooserBlock
from wagtail.images.edit_handlers import ImageChooserPanel from wagtail.images.edit_handlers import ImageChooserPanel
from wagtailmetadata.models import MetadataPageMixin from wagtailmetadata.models import MetadataPageMixin
from calendar_utils.models import CalendarMixin
from shared.models import ArticleMixin, SubpageMixin from shared.models import ArticleMixin, SubpageMixin
from tuning import help from tuning import help
...@@ -36,8 +37,10 @@ from .constants import ( ...@@ -36,8 +37,10 @@ from .constants import (
ARTICLES_PER_LINE, ARTICLES_PER_LINE,
ARTICLES_PER_PAGE, ARTICLES_PER_PAGE,
BLACK_ON_WHITE, BLACK_ON_WHITE,
CALENDAR_EVENTS_CHOICES,
COLOR_CHOICES, COLOR_CHOICES,
COLOR_CSS, COLOR_CSS,
FUTURE,
LEFT, LEFT,
RICH_TEXT_FEATURES, RICH_TEXT_FEATURES,
) )
...@@ -198,6 +201,39 @@ class MenuItemBlock(blocks.StructBlock): ...@@ -198,6 +201,39 @@ class MenuItemBlock(blocks.StructBlock):
label = "stránka" label = "stránka"
class CalendarAgendaBlock(blocks.StructBlock):
info = blocks.StaticBlock(
label="volba kalendáře",
admin_text="adresa kalendáře se zadává v nastavení hlavní stránky webu",
)
count = blocks.IntegerBlock(label="maximum událostí k zobrazení", default=10)
event_type = blocks.ChoiceBlock(
CALENDAR_EVENTS_CHOICES,
label="druh událostí",
default=FUTURE,
widget=forms.RadioSelect,
)
class Meta:
label = "kalendář agenda"
icon = "date"
group = "ostatní"
template = "uniweb/blocks/calendar_agenda.html"
def get_context(self, value, parent_context=None):
context = super().get_context(value, parent_context=parent_context)
count = value["count"]
page = context["page"]
if page.root_page.has_calendar:
if value["event_type"] == FUTURE:
context["events"] = page.root_page.calendar.future_events[:count]
else:
context["events"] = page.root_page.calendar.past_events[:count]
else:
context["events"] = []
return context
CONTENT_STREAM_BLOCKS = [ CONTENT_STREAM_BLOCKS = [
( (
"title", "title",
...@@ -242,6 +278,7 @@ CONTENT_STREAM_BLOCKS = [ ...@@ -242,6 +278,7 @@ CONTENT_STREAM_BLOCKS = [
), ),
), ),
("articles", ArticlesBlock()), ("articles", ArticlesBlock()),
("calendar_agenda", CalendarAgendaBlock()),
] ]
...@@ -249,7 +286,7 @@ class UniwebArticleTag(TaggedItemBase): ...@@ -249,7 +286,7 @@ class UniwebArticleTag(TaggedItemBase):
content_object = ParentalKey("uniweb.UniwebArticlePage", on_delete=models.CASCADE) content_object = ParentalKey("uniweb.UniwebArticlePage", on_delete=models.CASCADE)
class UniwebHomePage(Page, MetadataPageMixin): class UniwebHomePage(Page, MetadataPageMixin, CalendarMixin):
### FIELDS ### FIELDS
content = StreamField( content = StreamField(
...@@ -297,6 +334,7 @@ class UniwebHomePage(Page, MetadataPageMixin): ...@@ -297,6 +334,7 @@ class UniwebHomePage(Page, MetadataPageMixin):
], ],
"nastavení webu", "nastavení webu",
), ),
FieldPanel("calendar_url"),
CommentPanel(), CommentPanel(),
] ]
...@@ -330,6 +368,10 @@ class UniwebHomePage(Page, MetadataPageMixin): ...@@ -330,6 +368,10 @@ class UniwebHomePage(Page, MetadataPageMixin):
def root_page(self): def root_page(self):
return self return self
@property
def has_calendar(self):
return self.calendar_id is not None
class UniwebFlexiblePage(Page, SubpageMixin, MetadataPageMixin): class UniwebFlexiblePage(Page, SubpageMixin, MetadataPageMixin):
### FIELDS ### FIELDS
......
{% if page.root_page.has_calendar %}
{% for event in events %}
<div class="grid grid-cols-12 items-center calendar-table-row calendar-table-row--standalone">
<div class="col-span-2 text-blue-200 head-alt-md calendar-table-row__col">
<span>{{ event.begin|date:"j." }}</span>
</div>
<div class="col-span-8 grid grid-cols-3 calendar-table-row__col">
<div class="col-span-3 md:col-span-1">
<strong class="block">{{ event.begin|date:"l j. E"|capfirst }}</strong>
<p class="font-light text-sm mt-1">{{ event.duration }}</p>
</div>
<div class="col-span-3 md:col-span-2 mt-4 md:mt-0">
<strong class="block">{{ event.name }}</strong>
{% if event.description %}
<p class="font-light text-sm mt-1">{{ event.description }}</p>
{% endif %}
{% if event.location %}
<p class="font-light text-sm mt-1">{{ event.location }}</p>
{% endif %}
</div>
</div>
<div class="col-span-2 text-center font-light calendar-table-row__col">
{% if event.location %}
<a href="https://maps.google.com/maps?q={{ event.location }}" class="icon-link">
<i class="ico--location text-violet-300 mr-1" aria-hidden="true"></i>
<span>Mapa</span>
</a>
{% endif %}
</div>
</div>
{% empty %}
<div class="content-block">
<p>Žádné události.</p>
</div>
{% endfor %}
{% else %}
<div class="content-block">
<p>Žádné události.</p>
</div>
{% endif %}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment