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

elections2021: Candidates updates and refactorings

parent a36ddf77
No related branches found
No related tags found
2 merge requests!233Release,!232Volby
Showing with 133 additions and 142 deletions
...@@ -70,39 +70,27 @@ REGION_STC = "STC" ...@@ -70,39 +70,27 @@ REGION_STC = "STC"
REGION_ULK = "ULK" REGION_ULK = "ULK"
REGION_ZLK = "ZLK" REGION_ZLK = "ZLK"
REGION_CHOICES = ( REGION_DATA = (
(REGION_PHA, "Hlavní město Praha"), (REGION_PHA, "praha", "Hlavní město Praha", "Hlavním městě Praha"),
(REGION_JHC, "Jihočeský kraj"), (REGION_JHC, "jihocesky", "Jihočeský kraj", "Jihočeském kraji"),
(REGION_JHM, "Jihomoravský kraj"), (REGION_JHM, "jihomoravsky", "Jihomoravský kraj", "Jihomoravském kraji"),
(REGION_KVK, "Karlovarský kraj"), (REGION_KVK, "karlovarsky", "Karlovarský kraj", "Karlovarském kraji"),
(REGION_VYS, "Kraj Vysočina"), (REGION_VYS, "vysocina", "Kraj Vysočina", "Kraji Vysočina"),
(REGION_KHK, "Královéhradecký kraj"), (REGION_KHK, "kralovehradecky", "Královéhradecký kraj", "Královéhradeckém kraji"),
(REGION_LBK, "Liberecký kraj"), (REGION_LBK, "liberecky", "Liberecký kraj", "Libereckém kraji"),
(REGION_MSK, "Moravskoslezský kraj"), (REGION_MSK, "moravskoslezsky", "Moravskoslezský kraj", "Moravskoslezském kraji"),
(REGION_OLK, "Olomoucký kraj"), (REGION_OLK, "olomoucky", "Olomoucký kraj", "Olomouckém kraji"),
(REGION_PAK, "Pardubický kraj"), (REGION_PAK, "pardubicky", "Pardubický kraj", "Pardubickém kraji"),
(REGION_PLK, "Plzeňský kraj"), (REGION_PLK, "plzensky", "Plzeňský kraj", "Plzeňském kraji"),
(REGION_STC, "Středočeský kraj"), (REGION_STC, "stredocesky", "Středočeský kraj", "Středočeském kraji"),
(REGION_ULK, "Ústecký kraj"), (REGION_ULK, "ustecky", "Ústecký kraj", "Ústeckém kraji"),
(REGION_ZLK, "Zlínský kraj"), (REGION_ZLK, "zlinsky", "Zlínský kraj", "Zlínském kraji"),
) )
REGION_NAME_VARIANT = { REGION_CHOICES = [(code, name) for code, slug, name, name2 in REGION_DATA]
REGION_PHA: "Hlavním městě Praha", REGION_NAME_VARIANT = {code: name2 for code, slug, name, name2 in REGION_DATA}
REGION_JHC: "Jihočeském kraji", REGION_SLUGS = {slug: code for code, slug, name, name2 in REGION_DATA}
REGION_JHM: "Jihomoravském kraji", REGION_OPTIONS = [(slug, name) for code, slug, name, name2 in REGION_DATA]
REGION_KVK: "Karlovarském kraji",
REGION_VYS: "Kraji Vysočina",
REGION_KHK: "Královéhradeckém kraji",
REGION_LBK: "Libereckém kraji",
REGION_MSK: "Moravskoslezském kraji",
REGION_OLK: "Olomouckém kraji",
REGION_PAK: "Pardubickém kraji",
REGION_PLK: "Plzeňském kraji",
REGION_STC: "Středočeském kraji",
REGION_ULK: "Ústeckém kraji",
REGION_ZLK: "Zlínském kraji",
}
PIRATES = "pirati" PIRATES = "pirati"
STAN = "stan" STAN = "stan"
...@@ -223,7 +211,7 @@ MINISTRY_ARCHETYPES = { ...@@ -223,7 +211,7 @@ MINISTRY_ARCHETYPES = {
MINISTRY_COUNTRYSIDE: "rozvoj", MINISTRY_COUNTRYSIDE: "rozvoj",
MINISTRY_BUSINESS: "prumysl", MINISTRY_BUSINESS: "prumysl",
MINISTRY_JUSTICE: "spravedlnost", MINISTRY_JUSTICE: "spravedlnost",
MINISTRY_SCHOOLS: "vzdelani", MINISTRY_SCHOOLS: "vzdelavani",
MINISTRY_INTERIOR: "vnitro", MINISTRY_INTERIOR: "vnitro",
MINISTRY_FOREIGN: "vztahy", MINISTRY_FOREIGN: "vztahy",
MINISTRY_HEALTH: "zdravotnictvi", MINISTRY_HEALTH: "zdravotnictvi",
......
...@@ -4,6 +4,7 @@ from functools import cached_property ...@@ -4,6 +4,7 @@ from functools import cached_property
from django import forms from django import forms
from django.core.paginator import Paginator from django.core.paginator import Paginator
from django.db import models from django.db import models
from django.http import HttpResponseRedirect
from django.utils.translation import gettext_lazy from django.utils.translation import gettext_lazy
from modelcluster.contrib.taggit import ClusterTaggableManager from modelcluster.contrib.taggit import ClusterTaggableManager
from modelcluster.fields import ParentalKey from modelcluster.fields import ParentalKey
...@@ -69,7 +70,9 @@ from .constants import ( ...@@ -69,7 +70,9 @@ from .constants import (
PROGRAM_POINTS_PER_PAGE, PROGRAM_POINTS_PER_PAGE,
REGION_CHOICES, REGION_CHOICES,
REGION_NAME_VARIANT, REGION_NAME_VARIANT,
REGION_OPTIONS,
REGION_PHA, REGION_PHA,
REGION_SLUGS,
RESTRICTED_FEATURES, RESTRICTED_FEATURES,
STANDARD_FEATURES, STANDARD_FEATURES,
STYLE_CHOICES, STYLE_CHOICES,
...@@ -153,7 +156,17 @@ class Elections2021HomePage(Page, MetadataPageMixin): ...@@ -153,7 +156,17 @@ class Elections2021HomePage(Page, MetadataPageMixin):
@cached_property @cached_property
def candidates_list_page_url(self): def candidates_list_page_url(self):
return get_subpage_url(self, Elections2021CandidatesListPage) try:
return (
self.get_descendants()
.type(Elections2021CandidatesListPage)
.live()
.specific()
.first()
.get_region_list_url()
)
except (Page.DoesNotExist, AttributeError):
return "#"
@cached_property @cached_property
def candidates_map_page_url(self): def candidates_map_page_url(self):
...@@ -289,7 +302,9 @@ class Elections2021ArticlesPage(SubpageMixin, MetadataPageMixin, Page): ...@@ -289,7 +302,9 @@ class Elections2021ArticlesPage(SubpageMixin, MetadataPageMixin, Page):
return context return context
class Elections2021CandidatesListPage(SubpageMixin, MetadataPageMixin, Page): class Elections2021CandidatesListPage(
SubpageMixin, MetadataPageMixin, RoutablePageMixin, Page
):
### FIELDS ### FIELDS
photo = models.ForeignKey( photo = models.ForeignKey(
...@@ -334,35 +349,36 @@ class Elections2021CandidatesListPage(SubpageMixin, MetadataPageMixin, Page): ...@@ -334,35 +349,36 @@ class Elections2021CandidatesListPage(SubpageMixin, MetadataPageMixin, Page):
def get_context(self, request): def get_context(self, request):
context = super().get_context(request) context = super().get_context(request)
context["region_options"] = REGION_OPTIONS
return context
region_candidates_top = defaultdict(list) def get_region_list_url(self, slug=None):
region_candidates_bottom = defaultdict(list) if slug is None:
slug = list(REGION_SLUGS.keys())[0]
return self.url + self.reverse_subpage("region_list", args=(slug,))
@route(r"^$")
@route(r"^kraj/$")
@route(r"^kraj/([a-z]+)/$")
def region_list(self, request, param=None):
region = param if param in REGION_SLUGS else None
if not region:
return HttpResponseRedirect(self.get_region_list_url())
candidates = ( candidates = (
self.get_children() self.get_children()
.filter(elections2021candidatepage__region=REGION_SLUGS[region])
.live() .live()
.specific() .specific()
.order_by("elections2021candidatepage__number") .order_by("elections2021candidatepage__number")
) )
for can in candidates: context = {
if len(region_candidates_top[can.region]) < TOP_CANDIDATES_NUM: "active_region": region,
region_candidates_top[can.region].append(can) "candidates_top": candidates[:TOP_CANDIDATES_NUM],
else: "candidates_bottom": candidates[TOP_CANDIDATES_NUM:],
region_candidates_bottom[can.region].append(can) }
return self.render(request, context_overrides=context)
context["region_candidates_top"] = dict(region_candidates_top)
context["region_candidates_bottom"] = dict(region_candidates_bottom)
context["region_choices"] = REGION_CHOICES
context["region_codes"] = [code for code, _ in REGION_CHOICES]
active_region = request.GET.get("kraj", REGION_PHA)
if active_region in context["region_codes"]:
context["active_region"] = active_region
else:
context["active_region"] = REGION_PHA
return context
class Elections2021CandidatesMapPage(SubpageMixin, MetadataPageMixin, Page): class Elections2021CandidatesMapPage(SubpageMixin, MetadataPageMixin, Page):
...@@ -505,6 +521,11 @@ class Elections2021CandidatePage(SubpageMixin, MetadataPageMixin, Page): ...@@ -505,6 +521,11 @@ class Elections2021CandidatePage(SubpageMixin, MetadataPageMixin, Page):
def is_pirate(self): def is_pirate(self):
return self.party == PIRATES return self.party == PIRATES
def get_region_list_url(self):
slug = next(slug for slug, code in REGION_SLUGS.items() if code == self.region)
candidates_list = Elections2021CandidatesListPage.objects.live().first()
return candidates_list.get_region_list_url(slug)
class Elections2021ProgramPage( class Elections2021ProgramPage(
SubpageMixin, MetadataPageMixin, RoutablePageMixin, Page SubpageMixin, MetadataPageMixin, RoutablePageMixin, Page
......
This diff is collapsed.
<svg id="vzdelavani_a_veda" data-name="vzdelavani a veda" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 141.73 141.73">
<defs>
<style>
.cls-1 {
fill: none;
}
.cls-2 {
clip-path: url(#clip-path);
}
.cls-3 {
fill: #000;
}
</style>
<clipPath id="clip-path">
<rect class="cls-1" x="17.01" y="25.83" width="107.53" height="90.4"/>
</clipPath>
</defs>
<title>vzdelavani a veda</title>
<g class="cls-2">
<path class="cls-3" d="M39,66.55c-.86,1.85-.86,7-.86,7a12.14,12.14,0,0,1,4,9.22,13.16,13.16,0,0,1-2.37,7s9.14,11.07,31.61,11.07,30.11-8.43,32.26-11.07a8.08,8.08,0,0,0,1.83-5.53V66.15s-28.93,12-31,12.78a8.38,8.38,0,0,1-5.7,0C67.45,78.4,39,66.55,39,66.55m85.59-17.66c0-2-2.36-2.5-2.36-2.5L73.47,26.46a8.1,8.1,0,0,0-1.93-.62,3.72,3.72,0,0,0-1.4.53L20,46.91a3.17,3.17,0,0,0-1.29,2.24,3.29,3.29,0,0,0,1.08,2.24l11.83,5a63.1,63.1,0,0,0-3.55,9.22,30,30,0,0,0-.86,8.83,5.71,5.71,0,0,0-4.07,5.84,6.51,6.51,0,0,0,4,6.28s.22,5.53-3.22,14.23C22.16,105.19,17,111.47,17,111.47s3,2.55,4.82,3.73a5.5,5.5,0,0,0,5.83.35c1.72-1.05,4.48-3.89,5.66-9.93s-1-19.72-1-19.72,3.4-.3,3.4-5.17-3.83-5.89-3.83-5.89l.66-5.4a28.53,28.53,0,0,1,2.24-7.51c1-1.84,2.47-4,8.92-7.64S69.27,42.17,69.27,42.17s4-1.75,5.88.56-2.22,4.57-2.22,4.57L43.9,61s26.34,11.2,26.77,11.33a4,4,0,0,0,2.15,0l49.79-20.55a3.49,3.49,0,0,0,1.94-2.9"/>
</g>
</svg>
{% load static wagtailcore_tags wagtailimages_tags %} {% load static wagtailcore_tags wagtailimages_tags %}
<div class="candidate-card candidate-card--pirati-stan container-padding--zero sm:container-padding--auto "> <div class="candidate-card candidate-card--pirati-stan container-padding--zero sm:container-padding--auto ">
<div class="candidate-card__wrapper candidate-card-list__item-wrapper {% if not candidate.is_pirate %}candidate-card-list__item-wrapper--stan-candidate{% endif %}"> <div class="candidate-card__wrapper h-full candidate-card-list__item-wrapper {% if not candidate.is_pirate %}candidate-card-list__item-wrapper--stan-candidate{% endif %}">
<div class="card candidate-card__body elevation-0 hover:elevation-10 transition duration-200"> <div class="card candidate-card__body elevation-2 sm:elevation-0 hover:elevation-10 transition duration-200 h-full">
<div class="candidate-card__avatar sm:pl-0"> <div class="candidate-card__avatar sm:pl-0">
<div class="candidate-card__position">{{ candidate.number }}</div> <div class="candidate-card__position">{{ candidate.number }}</div>
<a href="{% pageurl candidate %}" data-href="{% pageurl candidate %}"> <a href="{% pageurl candidate %}" data-href="{% pageurl candidate %}">
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
</div> </div>
<div class="candidate-card__bio"> <div class="candidate-card__bio">
<h1 class="head-heavy-xs"><a href="{% pageurl candidate %}" data-href="{% pageurl candidate %}">{{ candidate.title }}</a></h1> <h1 class="head-heavy-xs"><a href="{% pageurl candidate %}" data-href="{% pageurl candidate %}">{{ candidate.title }}</a></h1>
<a href="mailto:{{ candidate.email }}" class="candidate-card__bio-item block mb-4">{{ candidate.email|default:"" }}</a> <a href="mailto:{{ candidate.email }}" class="candidate-card__bio-item block pb-4 pt-3 md:pt-0 md:pb-4">{{ candidate.email|default:"" }}</a>
<h2 class="candidate-card__bio-item">{{ candidate.occupation }}</h2> <h2 class="candidate-card__bio-item">{{ candidate.occupation }}</h2>
<h2 class="head-allcaps-4xs mt-4">{{ candidate.city }}</h2> <h2 class="head-allcaps-4xs mt-4">{{ candidate.city }}</h2>
</div> </div>
......
{% load static wagtailcore_tags wagtailimages_tags %}
<a href="{% pageurl candidate %}" data-href="{% pageurl candidate %}" class="candidate-table-row">
<div class="candidate-table-row__position head-allcaps-heavy-2xs text-right">{{ candidate.number }}</div>
<div class="avatar candidate-table-row__avatar">
{% image candidate.photo fill-40x40 %}
</div>
<div class="candidate-table-row__name head-heavy-2xs font-bold">{{ candidate.title }}</div>
<div class="candidate-table-row__bio font-condensed">{{ candidate.age }} let, {{ candidate.occupation }}, {{ candidate.city }}</div>
<div class="candidate-table-row__affiliation">
<div class="w-6 mr-2">
{% if candidate.is_pirate %}
<img src="{% static "elections2021/images/logo-pirati-21px.svg" %}">
{% else %}
<img src="{% static "elections2021/images/logo-stan-21px.svg" %}">
{% endif %}
</div>
<span class="font-bold font-condensed">{{ candidate.party_name }}</span>
</div>
</a>
...@@ -5,10 +5,7 @@ ...@@ -5,10 +5,7 @@
<h1 class="head-alt-md sm:head-alt-lg pt-1 max-w-sm">{{ page.title }}</h1> <h1 class="head-alt-md sm:head-alt-lg pt-1 max-w-sm">{{ page.title }}</h1>
</div> </div>
<div class="hidden lg:block lg:row-span-2 lg:col-span-3 order-2 h-full 2xl:absolute 2xl:right-0 2xl:w-1/3"> <div class="hidden lg:block lg:row-span-2 lg:col-span-3 order-2 h-full 2xl:absolute 2xl:right-0 2xl:w-1/3">
{% if page.photo %} {% image page.photo fill-618x256 class="object-cover w-full h-full" %}
{% image page.photo fill-618x256 as img %}
<img class="object-cover w-full h-full" src="{{ img.url }}">
{% endif %}
</div> </div>
</div> </div>
</article> </article>
...@@ -4,10 +4,10 @@ ...@@ -4,10 +4,10 @@
{% block content %} {% block content %}
<article class="hero hero--image pt-24 pb-20 lg:pt-28 pb-10 candidate-detail__hero "> <article class="hero hero--image pt-24 pb-20 lg:pt-28 pb-10 candidate-detail__hero ">
<div class="container container--default text-center lg:text-left"> <div class="container container--default text-center lg:text-left">
<a href="{{ page.root_page.candidates_list_page_url }}?kraj={{ page.region }}" class="btn text-sm btn--hoveractive btn--to-black"> <a href="{{ page.get_region_list_url }}" class="btn text-sm btn--hoveractive btn--to-black">
<div class="btn__body leading-5 bg-acidgreen text-black hover:text-white px-10 py-3">zpět na výpis</div> <div class="btn__body leading-5 bg-acidgreen text-black hover:text-white px-10 py-3">zpět na výpis</div>
</a> </a>
<h1 class="head-alt-md md:head-alt-xl mt-9 text-black">{{ page.title }}</h1> <h1 class="head-alt-md md:head-alt-xl mt-9 text-black w-full lg:w-2/5 xl:w-2/3 text-center lg:text-left">{{ page.title }}</h1>
</div> </div>
</article> </article>
...@@ -83,7 +83,8 @@ ...@@ -83,7 +83,8 @@
</div> </div>
</div> </div>
</div> </div>
</div></section> </div>
</section>
</div> </div>
</main> </main>
</div> </div>
......
...@@ -2,97 +2,38 @@ ...@@ -2,97 +2,38 @@
{% load static wagtailcore_tags wagtailimages_tags %} {% load static wagtailcore_tags wagtailimages_tags %}
{% block content %} {% block content %}
<article class="relative bg-lemon md:bg-split-color px-4 md:pl-8 md:pr-0 2xl:px-8 hero py-0 w-full ">
<div class="2xl:container w-auto bg-lemon md:pl-20 pr-0 grid lg:grid-rows-2 lg:grid-cols-7 items-center 2xl:mx-auto"> {% include "elections2021/_page_header.html" %}
<div class="lg:row-span-1 lg:col-span-4 order-1 pt-14 md:pr-20">
<h1 class="head-alt-md sm:head-alt-lg max-w-md">{{ page.title }}</h1>
</div>
{% comment %}
<div class="lg:row-span-1 lg:col-span-4 order-3 pb-14 md:pr-20">
<div class="hidden md:block pt-8">
<div class="switch">
<a class="switch__item switch__item--active">seznam</a>
<a href="{{ page.root_page.candidates_map_page_url }}" class="switch__item">mapa</a>
</div>
</div>
</div>
{% endcomment %}
<div class="hidden lg:block lg:row-span-2 lg:col-span-3 order-2 h-full 2xl:absolute 2xl:right-0 2xl:w-1/3">
{% image page.photo fill-618x256 as img %}
<img class="object-cover w-full h-full" src="{{ img.url }}">
</div>
</div>
</article>
<div class="container container--default py-8 lg:py-24"> <div class="container container--default py-8 lg:py-24">
<section class="text-center relative"> <section class="text-center relative">
<h1 class="head-alt-md pt-1 mb-8">Výpis kandidátů</h1> <div class="select left-0 top-0 w-full md:w-auto inline-flex mb-8 md:mb-0">
<select id="region_select" class="select__control form-field__control bg-acidgreen text-black" data-chosen="">
<div class="select md:absolute left-0 top-0 text-white w-full md:w-auto inline-flex md:float-left mb-8 md:mb-0"> {% for slug, name in region_options %}
<select id="region_select" class="select__control form-field__control bg-black" data-chosen=""> <option value="{{ slug }}" {% if slug == active_region %}selected=""{% endif %}>{{ name }}</option>
{% for code, name in region_choices %}
<option value="{{ code }}" {% if code == active_region %}selected=""{% endif %}>{{ name }}</option>
{% endfor %} {% endfor %}
</select> </select>
</div> </div>
<main class="md:mt-20"> <main class="md:mt-20">
{% for code, candidates in region_candidates_top.items %}
<div id="candidates_top_{{ code }}" {% if code != active_region %}class="hidden"{% endif %}>
<div class="candidate-card-list grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4"> <div class="candidate-card-list grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4">
{% for candidate in candidates %} {% for candidate in candidates_top %}
{% include "elections2021/_candidate_card.html" %} {% include "elections2021/_candidate_card.html" %}
{% endfor %} {% endfor %}
</div> </div>
</div>
{% endfor %}
{% for code, candidates in region_candidates_bottom.items %}
<div id="candidates_bottom_{{ code }}" {% if code != active_region %}class="hidden"{% endif %}>
<div class="candidate-table container-padding--zero lg:container-padding--auto pt-8"> <div class="candidate-table container-padding--zero lg:container-padding--auto pt-8">
{% for candidate in candidates %} {% for candidate in candidates_bottom %}
<a href="{% pageurl candidate %}" data-href="{% pageurl candidate %}" class="candidate-table-row"> {% include "elections2021/_candidate_list_item.html" %}
<div class="candidate-table-row__position head-allcaps-heavy-2xs text-right">{{ candidate.number }}</div>
<div class="avatar candidate-table-row__avatar">
{% image candidate.photo fill-40x40 %}
</div>
<div class="candidate-table-row__name head-heavy-2xs font-bold">{{ candidate.title }}</div>
<div class="candidate-table-row__bio font-condensed">{{ candidate.age }} let, {{ candidate.occupation }}, {{ candidate.city }}</div>
<div class="candidate-table-row__affiliation">
<div class="w-6 mr-2">
{% if candidate.is_pirate %}
<img src="{% static "elections2021/images/logo-pirati-21px.svg" %}">
{% else %}
<img src="{% static "elections2021/images/logo-stan-21px.svg" %}">
{% endif %}
</div>
<span class="font-bold font-condensed">{{ candidate.party_name }}</span>
</div>
</a>
{% endfor %} {% endfor %}
</div> </div>
</div>
{% endfor %}
<script> <script>
var codes = ['{{ region_codes|join:"','" }}']; var baseUrl = "{% pageurl page %}";
var regionSelect = document.getElementById('region_select'); var regionSelect = document.getElementById('region_select');
regionSelect.addEventListener('change', function(e) { regionSelect.addEventListener('change', function(e) {
var activeCode = this.value; location.href = baseUrl + "kraj/" + this.value + "/";
for (var i = 0; i < codes.length; i++) {
var code = codes[i];
var classValue = (code == activeCode) ? '' : 'hidden';
var top = document.getElementById('candidates_top_' + code);
var bottom = document.getElementById('candidates_bottom_' + code);
if (top !== null) {
top.setAttribute('class', classValue);
}
if (bottom !== null) {
bottom.setAttribute('class', classValue);
}
}
window.history.replaceState('', '', '?kraj=' + activeCode);
}); });
</script> </script>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment