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

senat campaign: Web settings in root page

parent 4de25475
Branches
No related tags found
1 merge request!13senat campaign: Web settings in root page
Pipeline #599 passed
......@@ -63,7 +63,9 @@ class CalendarMixin(models.Model):
calendar_url = models.URLField(
"URL kalendáře ve formátu iCal", blank=True, null=True
)
calendar = models.ForeignKey(Calendar, null=True, on_delete=models.PROTECT)
calendar = models.ForeignKey(
Calendar, null=True, blank=True, on_delete=models.PROTECT
)
class Meta:
abstract = True
......
# Generated by Django 3.0.6 on 2020-05-25 17:51
import django.db.models.deletion
import wagtail.core.blocks
import wagtail.core.fields
import wagtail.images.blocks
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("calendar_utils", "0002_auto_20200523_0243"),
("senat_campaign", "0003_auto_20200523_0241"),
]
operations = [
migrations.AddField(
model_name="senatcampaignhomepage",
name="calendar",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.PROTECT,
to="calendar_utils.Calendar",
),
),
migrations.AddField(
model_name="senatcampaignhomepage",
name="calendar_url",
field=models.URLField(
blank=True, null=True, verbose_name="URL kalendáře ve formátu iCal"
),
),
migrations.AddField(
model_name="senatcampaignhomepage",
name="contacts",
field=wagtail.core.fields.StreamField(
[
(
"item",
wagtail.core.blocks.StructBlock(
[
("name", wagtail.core.blocks.CharBlock(label="jméno")),
(
"job",
wagtail.core.blocks.CharBlock(
label="pozice", required=False
),
),
(
"phone",
wagtail.core.blocks.CharBlock(
label="telefon", required=False
),
),
(
"email",
wagtail.core.blocks.EmailBlock(
label="email", required=False
),
),
(
"photo",
wagtail.images.blocks.ImageChooserBlock(
label="fotka"
),
),
]
),
)
],
blank=True,
verbose_name="kontaktní osoby",
),
),
migrations.AddField(
model_name="senatcampaignhomepage",
name="facebook",
field=models.URLField(blank=True, null=True, verbose_name="Facebook URL"),
),
migrations.AddField(
model_name="senatcampaignhomepage",
name="first_name",
field=models.CharField(default="", max_length=250, verbose_name="jméno"),
preserve_default=False,
),
migrations.AddField(
model_name="senatcampaignhomepage",
name="instagram",
field=models.URLField(blank=True, null=True, verbose_name="Instagram URL"),
),
migrations.AddField(
model_name="senatcampaignhomepage",
name="last_name",
field=models.CharField(default="", max_length=250, verbose_name="příjmení"),
preserve_default=False,
),
migrations.AddField(
model_name="senatcampaignhomepage",
name="linkedin",
field=models.URLField(blank=True, null=True, verbose_name="LinkedIn URL"),
),
migrations.AddField(
model_name="senatcampaignhomepage",
name="matomo_id",
field=models.IntegerField(
blank=True,
null=True,
verbose_name="Matomo ID pro sledování návštěvnosti",
),
),
migrations.AddField(
model_name="senatcampaignhomepage",
name="twitter",
field=models.URLField(blank=True, null=True, verbose_name="Twitter URL"),
),
migrations.AlterField(
model_name="senatcampaignwebsettings",
name="calendar",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.PROTECT,
to="calendar_utils.Calendar",
),
),
]
from django.db import models
from django.utils.translation import gettext_lazy
from wagtail.admin.edit_handlers import (
FieldPanel,
HelpPanel,
MultiFieldPanel,
ObjectList,
StreamFieldPanel,
TabbedInterface,
......@@ -16,7 +19,19 @@ from wagtail.images.edit_handlers import ImageChooserPanel
from calendar_utils.models import CalendarMixin
class SenatCampaignHomePage(Page):
class ContactBlock(blocks.StructBlock):
name = blocks.CharBlock(label="jméno")
job = blocks.CharBlock(label="pozice", required=False)
phone = blocks.CharBlock(label="telefon", required=False)
email = blocks.EmailBlock(label="email", required=False)
photo = ImageChooserBlock(label="fotka")
class Meta:
icon = "person"
label = "kontaktní osoba"
class SenatCampaignHomePage(Page, CalendarMixin):
# top section
headline = models.CharField("podtitulek pod jménem", max_length=250, blank=True)
top_photo = models.ForeignKey(
......@@ -62,17 +77,73 @@ class SenatCampaignHomePage(Page):
verbose_name="transparentní financování",
blank=True,
)
# settings
first_name = models.CharField("jméno", max_length=250)
last_name = models.CharField("příjmení", max_length=250)
facebook = models.URLField("Facebook URL", blank=True, null=True)
instagram = models.URLField("Instagram URL", blank=True, null=True)
twitter = models.URLField("Twitter URL", blank=True, null=True)
linkedin = models.URLField("LinkedIn URL", blank=True, null=True)
contacts = StreamField(
[("item", ContactBlock())], verbose_name="kontaktní osoby", blank=True
)
matomo_id = models.IntegerField(
"Matomo ID pro sledování návštěvnosti", blank=True, null=True
)
content_panels = Page.content_panels + [
FieldPanel("headline"),
ImageChooserPanel("top_photo"),
FieldPanel("claim"),
FieldPanel("about_left", classname="full"),
FieldPanel("about_right", classname="full"),
StreamFieldPanel("about_gallery"),
MultiFieldPanel(
[
FieldPanel("first_name"),
FieldPanel("last_name"),
FieldPanel("headline"),
],
heading="úvod",
),
MultiFieldPanel(
[ImageChooserPanel("top_photo"), FieldPanel("claim"),],
heading="úvodní foto",
),
MultiFieldPanel(
[
FieldPanel("about_left", classname="full"),
FieldPanel("about_right", classname="full"),
StreamFieldPanel("about_gallery"),
],
heading="kdo jsem",
),
StreamFieldPanel("financials"),
]
promote_panels = [
MultiFieldPanel(
[
HelpPanel(
"Název stránky na předchozím tabu slouží k rozlišení stránek "
"v Majáku. V prohlížeči se zobrazí tento titulek."
),
FieldPanel("seo_title"),
FieldPanel("search_description"),
],
gettext_lazy("Common page configuration"),
),
]
settings_panels = [
MultiFieldPanel(
[
FieldPanel("facebook"),
FieldPanel("instagram"),
FieldPanel("twitter"),
FieldPanel("linkedin"),
],
heading="Sociální sítě",
),
FieldPanel("calendar_url"),
FieldPanel("matomo_id"),
StreamFieldPanel("contacts"),
]
subpage_types = [
"senat_campaign.SenatCampaignNewsIndexPage",
"senat_campaign.SenatCampaignProgramPage",
......@@ -85,6 +156,44 @@ class SenatCampaignHomePage(Page):
class Meta:
verbose_name = "Senát kampaň"
@property
def root_page(self):
return self
@property
def full_name(self):
return f"{self.first_name} {self.last_name}"
@property
def has_program(self):
return self.get_descendants().type(SenatCampaignProgramPage).live().exists()
@property
def has_news(self):
return self.get_descendants().type(SenatCampaignNewsIndexPage).live().exists()
@property
def has_calendar(self):
return self.calendar_id is not None
@property
def has_donations(self):
# TODO
return False
@property
def cookies_page_url(self):
try:
return (
self.get_descendants()
.type(SenatCampaignCookiesPage)
.live()
.get()
.get_url()
)
except Page.DoesNotExist:
return "#"
def get_context(self, request):
context = super().get_context(request)
......@@ -126,12 +235,31 @@ class SenatCampaignNewsIndexPage(Page):
parent_page_types = ["senat_campaign.SenatCampaignHomePage"]
subpage_types = ["senat_campaign.SenatCampaignNewsPage"]
promote_panels = [
MultiFieldPanel(
[
FieldPanel("slug"),
FieldPanel("seo_title"),
FieldPanel("search_description"),
],
gettext_lazy("Common page configuration"),
),
]
settings_panels = []
# flag for rendering anchor links in menu
is_home = False
class Meta:
verbose_name = "Aktuality"
@property
def root_page(self):
if not hasattr(self, "_root_page"):
self._root_page = self.get_parent().specific
return self._root_page
def get_context(self, request):
context = super().get_context(request)
articles = self.get_children().live().order_by("-senatcampaignnewspage__date")
......@@ -158,6 +286,17 @@ class SenatCampaignNewsPage(Page):
ImageChooserPanel("photo"),
]
promote_panels = [
MultiFieldPanel(
[
FieldPanel("slug"),
FieldPanel("seo_title"),
FieldPanel("search_description"),
],
gettext_lazy("Common page configuration"),
),
]
parent_page_types = ["senat_campaign.SenatCampaignNewsIndexPage"]
subpage_types = []
......@@ -167,6 +306,14 @@ class SenatCampaignNewsPage(Page):
class Meta:
verbose_name = "Aktualita"
@property
def root_page(self):
if not hasattr(self, "_root_page"):
self._root_page = (
self.get_ancestors().type(SenatCampaignHomePage).specific().get()
)
return self._root_page
def get_context(self, request):
context = super().get_context(request)
context["related_articles"] = (
......@@ -203,6 +350,19 @@ class SenatCampaignProgramPage(Page):
StreamFieldPanel("content"),
]
promote_panels = [
MultiFieldPanel(
[
FieldPanel("slug"),
FieldPanel("seo_title"),
FieldPanel("search_description"),
],
gettext_lazy("Common page configuration"),
),
]
settings_panels = []
parent_page_types = ["senat_campaign.SenatCampaignHomePage"]
subpage_types = []
......@@ -212,6 +372,12 @@ class SenatCampaignProgramPage(Page):
class Meta:
verbose_name = "Program"
@property
def root_page(self):
if not hasattr(self, "_root_page"):
self._root_page = self.get_parent().specific
return self._root_page
class SenatCampaignCookiesPage(Page):
body = RichTextField("obsah", blank=True)
......@@ -220,6 +386,19 @@ class SenatCampaignCookiesPage(Page):
FieldPanel("body", classname="full"),
]
promote_panels = [
MultiFieldPanel(
[
FieldPanel("slug"),
FieldPanel("seo_title"),
FieldPanel("search_description"),
],
gettext_lazy("Common page configuration"),
),
]
settings_panels = []
parent_page_types = ["senat_campaign.SenatCampaignHomePage"]
subpage_types = []
......@@ -229,17 +408,11 @@ class SenatCampaignCookiesPage(Page):
class Meta:
verbose_name = "Cookies"
class ContactBlock(blocks.StructBlock):
name = blocks.CharBlock(label="jméno")
job = blocks.CharBlock(label="pozice", required=False)
phone = blocks.CharBlock(label="telefon", required=False)
email = blocks.EmailBlock(label="email", required=False)
photo = ImageChooserBlock(label="fotka")
class Meta:
icon = "person"
label = "kontaktní osoba"
@property
def root_page(self):
if not hasattr(self, "_root_page"):
self._root_page = self.get_parent().specific
return self._root_page
@register_setting
......
{% load static wagtailuserbar wagtailcore_tags wagtailsettings_tags wagtailimages_tags %}
{% with web_settings=settings.senat_campaign.SenatCampaignWebSettings %}
{% load static wagtailuserbar wagtailcore_tags wagtailimages_tags %}
<!doctype html>
<html lang="cs">
<head>
......@@ -27,11 +26,11 @@
{% if page.seo_title %}
<title>{{ page.seo_title }}</title>
{% else %}
<title>{{ page.title }} | {{ web_settings.full_name }}</title>
<title>{{ page.title }} | {{ page.root_page.full_name }}</title>
{% endif %}
<!-- OpenGraph info -->
<meta property="og:title" content="{% firstof page.seo_title page.title web_settings.full_name %}" />
<meta property="og:title" content="{% firstof page.seo_title page.title page.root_page.full_name %}" />
<meta property="og:type" content="website" />
<meta property="og:locale" content="cs_CZ" />
<meta property="og:url" content="{{ page.full_url }}" />
......@@ -54,7 +53,7 @@
<link href="{% static "senat_campaign/assets/css/style.css" %}" rel="stylesheet">
<link href="{% static "senat_campaign/assets/css/icons.css" %}" rel="stylesheet">
{% if not request.is_preview and web_settings.matomo_id %}
{% if not request.is_preview and page.root_page.matomo_id %}
<!-- Matomo -->
<script type="text/javascript">
var _paq = window._paq || [];
......@@ -63,7 +62,7 @@
(function() {
var u="//matomo.pirati.cz/";
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', '{{ web_settings.matomo_id }}']);
_paq.push(['setSiteId', '{{ page.root_page.matomo_id }}']);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
})();
......@@ -86,7 +85,7 @@
</div>
</div>
<div class="col-md-6 text-right">
{% if web_settings.has_donations %}
{% if page.root_page.has_donations %}
{# TODO #}
<a href="#" class="btn btn-success support_buton btn-sm">Přispěj!<i class="icon-heart ml-2" title="Ikona srdce"></i></a>
{% endif %}
......@@ -100,8 +99,8 @@
<!-- Candidate name -->
<div class="brand-wrapper">
<a class="navbar-brand navbar-brand--primary" href="/">{{ web_settings.first_name }} <strong>{{ web_settings.last_name }}</strong></a>
<a class="navbar-brand navbar-brand--alt" href="/">{{ web_settings.first_name|first }}. <strong>{{ web_settings.last_name }}</strong></a>
<a class="navbar-brand navbar-brand--primary" href="/">{{ page.root_page.first_name }} <strong>{{ page.root_page.last_name }}</strong></a>
<a class="navbar-brand navbar-brand--alt" href="/">{{ page.root_page.first_name|first }}. <strong>{{ page.root_page.last_name }}</strong></a>
</div>
<!-- Mobile menu toggler -->
......@@ -121,7 +120,7 @@
<a class="nav-link" href="/#top">Úvod</a>
{% endif %}
</li>
{% if web_settings.has_program %}
{% if page.root_page.has_program %}
<li class="nav-item">
{% if page.is_home %}
<a class="nav-link js-scroll-anchor" href="#priority">Priority</a>
......@@ -137,7 +136,7 @@
<a class="nav-link" href="/#kdojsem">Kdo jsem</a>
{% endif %}
</li>
{% if web_settings.has_news %}
{% if page.root_page.has_news %}
<li class="nav-item">
{% if page.is_home %}
<a class="nav-link js-scroll-anchor" href="#aktuality">Aktuality</a>
......@@ -146,7 +145,7 @@
{% endif %}
</li>
{% endif %}
{% if web_settings.has_calendar %}
{% if page.root_page.has_calendar %}
<li class="nav-item">
{% if page.is_home %}
<a class="nav-link js-scroll-anchor" href="#kalendar">Kalendář</a>
......@@ -169,7 +168,7 @@
<div class="header__socials header__socials--mobile d-xl-none mb-2">
{% include "senat_campaign/socials_snippet.html" %}
</div>
{% if web_settings.has_donations %}
{% if page.root_page.has_donations %}
{# TODO #}
<a href="#" class="btn btn-success support_buton btn-sm d-xl-none mb-3">Přispěj!<i class="icon-heart ml-2" title="Ikona srdce"></i></a>
{% endif %}
......@@ -199,7 +198,7 @@
<div class="row">
{% for contact in web_settings.contacts %}
{% for contact in page.root_page.contacts %}
<div class="col-12 col-md-6 col-xl-4 mb-4 mb-xl-0">
<div class="person">
<div class="person__photo">
......@@ -233,10 +232,10 @@
<div class="container">
<div class="row">
<div class="col-12 col-md-6 mb-3 mb-md-0">
<p class="mb-0">{% now "Y" %} | Zadavatel: {{ web_settings.full_name }} | Zpracovatel: Česká pirátská strana</p>
<p class="mb-0">{% now "Y" %} | Zadavatel: {{ page.root_page.full_name }} | Zpracovatel: Česká pirátská strana</p>
</div><!-- /column -->
<div class="col-12 col-md-6 text-md-right">
<p class="mb-0">Tento web využívá soubory cookies - <a href="{{ web_settings.cookies_page_url }}">více informací</a></p>
<p class="mb-0">Tento web využívá soubory cookies - <a href="{{ page.root_page.cookies_page_url }}">více informací</a></p>
</div><!-- /column -->
</div><!-- /row -->
</div><!-- /container -->
......@@ -254,4 +253,3 @@
</body>
</html>
{% endwith %}
......@@ -11,11 +11,11 @@
<div class="row align-items-center">
<div class="col-12 col-md-7 col-lg-7 mb-5 mb-md-0 py-4 text-center text-md-left">
<h1 class="lead homepage-heading">{{ web_settings.full_name }}</h1>
<h1 class="lead homepage-heading">{{ page.root_page.full_name }}</h1>
<p class="lead mb-5">{{ page.headline }}</p>
<div class="row align-items-center">
{% if web_settings.has_program %}
{% if page.root_page.has_program %}
<div class="col-12 col-lg-auto mb-4 mb-lg-0">
<a href="#priority" class="btn btn-dark btn-lg js-scroll-anchor">Moje priority <i class="icon-chevron-right ml-2"></i></a>
</div><!-- /column -->
......@@ -32,7 +32,7 @@
<div class="col-12 col-md-5 offset-lg-1 col-lg-4 text-center">
{% if page.top_photo %}
{% image page.top_photo width-350 as top_photo %}
<img data-src="{{ top_photo.url }}" class="lazyload img-fluid mb-4" alt="{{ web_settings.full_name }}">
<img data-src="{{ top_photo.url }}" class="lazyload img-fluid mb-4" alt="{{ page.root_page.full_name }}">
{% endif %}
<h3 class="lead mb-0">{% if page.claim %}„{{ page.claim }}“{% endif %}</h3>
</div><!-- /column -->
......@@ -42,7 +42,7 @@
</section>
{% if web_settings.has_program %}
{% if page.root_page.has_program %}
<section class="section--primary" id="priority">
<div class="container">
<div class="row">
......@@ -133,7 +133,7 @@
{% endif %}
{% if web_settings.has_donations %}
{% if page.root_page.has_donations %}
<section class="section--black">
<div class="container">
<div class="row align-items-center">
......@@ -150,8 +150,8 @@
{% endif %}
{% if web_settings.has_news %}
<section class="section--primary{% if web_settings.has_calendar %} section--no-bottom-padding{% endif %}" id="aktuality">
{% if page.root_page.has_news %}
<section class="section--primary{% if page.root_page.has_calendar %} section--no-bottom-padding{% endif %}" id="aktuality">
<div class="container">
<h2 class="lead page-subheading mb-4">Aktuality</h2>
......@@ -184,7 +184,7 @@
{% endif %}
{% if web_settings.has_calendar %}
{% if page.root_page.has_calendar %}
<section class="section--primary" id="kalendar">
<div class="container">
......@@ -201,7 +201,7 @@
</div><!-- /calendar__left -->
<div class="calendar__right">
{% for event in web_settings.calendar.actual_events %}
{% for event in page.root_page.calendar.actual_events %}
{% include "senat_campaign/calendar_event_snippet.html" %}
{% empty %}
<div class="calendar__row__content">
......@@ -247,7 +247,7 @@
{% endif %}
{% if web_settings.has_calendar %}
{% if page.root_page.has_calendar %}
<!-- Calendar modal -->
<div class="modal fade calendar__modal" id="calendarModal" tabindex="-1" role="dialog"
aria-labelledby="calendarModalTitle" aria-hidden="true">
......@@ -278,7 +278,7 @@
<div class="calendar__right">
{% for event in web_settings.calendar.future_events %}
{% for event in page.root_page.calendar.future_events %}
{% include "senat_campaign/calendar_event_snippet.html" %}
{% empty %}
<div class="calendar__row__content">
......@@ -292,7 +292,7 @@
<div class="tab-pane fade" id="pastEvents" role="tabpanel" aria-labelledby="pastEvents-tab">
<div class="calendar__right">
{% for event in web_settings.calendar.past_events|slice:":10" %}
{% for event in page.root_page.calendar.past_events|slice:":10" %}
{% include "senat_campaign/calendar_event_snippet.html" %}
{% empty %}
<div class="calendar__row__content">
......
......@@ -51,11 +51,11 @@
</div><!-- /column -->
{% if web_settings.facebook %}
{% if page.root_page.facebook %}
<div class="col-12 col-lg-4 offset-xl-1 text-center">
<h3 class="lead mb-3">Z mého facebooku</h3>
<iframe src="https://www.facebook.com/plugins/page.php?href={{ web_settings.facebook }}&tabs=timeline&width=290&height=500&small_header=true&adapt_container_width=true&hide_cover=true&show_facepile=false&appId=410144066050191" width="290" height="500" style="border:none;overflow:hidden" scrolling="no" frameborder="0" allowTransparency="true" allow="encrypted-media"></iframe>
<iframe src="https://www.facebook.com/plugins/page.php?href={{ page.root_page.facebook }}&tabs=timeline&width=290&height=500&small_header=true&adapt_container_width=true&hide_cover=true&show_facepile=false&appId=410144066050191" width="290" height="500" style="border:none;overflow:hidden" scrolling="no" frameborder="0" allowTransparency="true" allow="encrypted-media"></iframe>
</div><!-- /column -->
{% endif %}
......
{% if web_settings.facebook %}
<a href="{{ web_settings.facebook }}" target="_blank"><i class="icon-facebook-f" title="Facebooková stránka"></i></a>
{% if page.root_page.facebook %}
<a href="{{ page.root_page.facebook }}" target="_blank"><i class="icon-facebook-f" title="Facebooková stránka"></i></a>
{% endif %}
{% if web_settings.twitter %}
<a href="{{ web_settings.twitter }}" target="_blank"><i class="icon-twitter" title="Profil na Twitteru"></i></a>
{% if page.root_page.twitter %}
<a href="{{ page.root_page.twitter }}" target="_blank"><i class="icon-twitter" title="Profil na Twitteru"></i></a>
{% endif %}
{% if web_settings.instagram %}
<a href="{{ web_settings.instagram }}" target="_blank"><i class="icon-instagram" title="Profil na Instagramu"></i></a>
{% if page.root_page.instagram %}
<a href="{{ page.root_page.instagram }}" target="_blank"><i class="icon-instagram" title="Profil na Instagramu"></i></a>
{% endif %}
{% if web_settings.linkedin %}
<a href="{{ web_settings.linkedin }}" target="_blank"><i class="icon-linkedin" title="Profil na LinkedIn"></i></a>
{% if page.root_page.linkedin %}
<a href="{{ page.root_page.linkedin }}" target="_blank"><i class="icon-linkedin" title="Profil na LinkedIn"></i></a>
{% endif %}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment