From 792647a5569f45e4247ea69b559680c704bb8d8c Mon Sep 17 00:00:00 2001 From: Ondrej Rehounek <ondra.rehounek@seznam.cz> Date: Thu, 18 Nov 2021 09:14:27 +0100 Subject: [PATCH] district: Person snippet refactor --- district/models.py | 22 +++++++++------ district/templates/district/base.html | 6 ++-- .../district/blocks/people_group_block.html | 2 +- .../district/district_article_page.html | 2 +- .../district/district_contact_page.html | 2 +- .../district/district_person_page.html | 2 +- region/templates/region/base.html | 6 ++-- .../templates/region/region_contact_page.html | 2 +- .../templates/region/region_people_page.html | 4 +-- .../templates/region/region_person_page.html | 4 +-- .../shared/person_badge_snippet.html | 28 ++++++++++--------- 11 files changed, 44 insertions(+), 36 deletions(-) diff --git a/district/models.py b/district/models.py index b0e965dc5..c111fcf61 100644 --- a/district/models.py +++ b/district/models.py @@ -485,14 +485,6 @@ class DistrictPersonPage(SubpageMixin, MetadataPageMixin, Page): else self.root_page.fallback_image ) - @property - def pageperex(self): - """ - Vraci perex Pirata nejblizzsi lokalnimu kontextu. Zamerne jiny nazev, aby - v template bylo na vyber z x.perex, x.person.perex a x.pageperex - """ - return self.perex or self.person.perex - def get_context(self, request): context = super().get_context(request) # Na strance detailu cloveka se vpravo zobrazuji 3 dalsi nahodne profily @@ -503,6 +495,20 @@ class DistrictPersonPage(SubpageMixin, MetadataPageMixin, Page): context["random_people"] = context["random_people"][:3] return context + def get_email(self): + return self.person.email if self.person.email else self.email + + def get_phone(self): + return self.person.phone if self.person.phone else self.phone + + @property + def pageperex(self): + """ + Vraci perex Pirata nejblizzsi lokalnimu kontextu. Zamerne jiny nazev, aby + v template bylo na vyber z x.perex, x.person.perex a x.pageperex + """ + return self.perex or self.person.perex + class DistrictPeoplePage(SubpageMixin, MetadataPageMixin, Page): ### FIELDS diff --git a/district/templates/district/base.html b/district/templates/district/base.html index 879a80090..dd96bd42e 100644 --- a/district/templates/district/base.html +++ b/district/templates/district/base.html @@ -276,13 +276,13 @@ <div class="container container--default"> <div class="grid gap-4 grid-cols-1 md:grid-cols-2 xl:grid-cols-3"> {% if page.root_page.footperson_coord %} - {% include "shared/person_badge_snippet.html" with person=page.root_page.footperson_coord title="Koordinátor" %} + {% include "shared/person_badge_snippet.html" with person_page=page.root_page.footperson_coord title="Koordinátor" %} {% endif %} {% if page.root_page.footperson_electman %} - {% include "shared/person_badge_snippet.html" with person=page.root_page.footperson_electman title="Volební manažer" %} + {% include "shared/person_badge_snippet.html" with person_page=page.root_page.footperson_electman title="Volební manažer" %} {% endif %} {% if page.root_page.footperson_media %} - {% include "shared/person_badge_snippet.html" with person=page.root_page.footperson_media title="Kontakt pro média" %} + {% include "shared/person_badge_snippet.html" with person_page=page.root_page.footperson_media title="Kontakt pro média" %} {% endif %} </div> </div> diff --git a/district/templates/district/blocks/people_group_block.html b/district/templates/district/blocks/people_group_block.html index 44907e43a..af30db41a 100644 --- a/district/templates/district/blocks/people_group_block.html +++ b/district/templates/district/blocks/people_group_block.html @@ -2,7 +2,7 @@ {{ self.group_title }} </h2> <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 row-gap-8 col-gap-8"> - {% for person in self.person_list %} + {% for person_page in self.person_list %} {% include "shared/person_badge_snippet.html" %} {% endfor %} </div> diff --git a/district/templates/district/district_article_page.html b/district/templates/district/district_article_page.html index d0b86bcd9..6f1899b9e 100644 --- a/district/templates/district/district_article_page.html +++ b/district/templates/district/district_article_page.html @@ -38,7 +38,7 @@ {{ page.text|richtext }} {% if page.author_page %} - {% include "shared/person_badge_snippet.html" with person=page.author_page title="Autor" %} + {% include "shared/person_badge_snippet.html" with person_page=page.author_page title="Autor" %} {% endif %} </div> diff --git a/district/templates/district/district_contact_page.html b/district/templates/district/district_contact_page.html index ac8589568..730c806bc 100644 --- a/district/templates/district/district_contact_page.html +++ b/district/templates/district/district_contact_page.html @@ -16,7 +16,7 @@ <div> <h2 class="head-heavy-sm mb-2 lg:mb-4 mt-4">{{ item.value.name }}</h2> <div class="card elevation-3 p-3 mb-3"> - {% include "shared/person_badge_snippet.html" with person=item.value.person %} + {% include "shared/person_badge_snippet.html" with person_page=item.value.person %} </div> </div> diff --git a/district/templates/district/district_person_page.html b/district/templates/district/district_person_page.html index c2abb8506..c9ff2ed84 100644 --- a/district/templates/district/district_person_page.html +++ b/district/templates/district/district_person_page.html @@ -91,7 +91,7 @@ <h2>Lidé</h2> <div class="space-y-4 mt-4"> {% for person in random_people %} - {% include "shared/person_badge_snippet.html" with person=person skipcontacts=1 %} + {% include "shared/person_badge_snippet.html" with person_page=person skipcontacts=1 %} {% endfor %} </div> <a href="{{ page.root_page.people_page.url }}" diff --git a/region/templates/region/base.html b/region/templates/region/base.html index d616216d8..92e286f23 100644 --- a/region/templates/region/base.html +++ b/region/templates/region/base.html @@ -257,13 +257,13 @@ <div class="container container--default"> <div class="grid gap-4 grid-cols-1 md:grid-cols-2 xl:grid-cols-3"> {% if page.root_page.footperson_coord %} - {% include "shared/person_badge_snippet.html" with person=page.root_page.footperson_coord title="Koordinátor" %} + {% include "shared/person_badge_snippet.html" with person_page=page.root_page.footperson_coord title="Koordinátor" %} {% endif %} {% if page.root_page.footperson_electman %} - {% include "shared/person_badge_snippet.html" with person=page.root_page.footperson_electman title="Volební manažer" %} + {% include "shared/person_badge_snippet.html" with person_page=page.root_page.footperson_electman title="Volební manažer" %} {% endif %} {% if page.root_page.footperson_media %} - {% include "shared/person_badge_snippet.html" with person=page.root_page.footperson_media title="Kontakt pro média" %} + {% include "shared/person_badge_snippet.html" with person_page=page.root_page.footperson_media title="Kontakt pro média" %} {% endif %} </div> </div> diff --git a/region/templates/region/region_contact_page.html b/region/templates/region/region_contact_page.html index 66901d666..52654af8a 100644 --- a/region/templates/region/region_contact_page.html +++ b/region/templates/region/region_contact_page.html @@ -16,7 +16,7 @@ <div> <h2 class="head-heavy-sm mb-2 lg:mb-4 mt-4">{{ item.value.name }}</h2> <div class="card elevation-3 p-3 mb-3"> - {% include "shared/person_badge_snippet.html" with person=item.value.person %} + {% include "shared/person_badge_snippet.html" with person_page=item.value.person %} </div> </div> diff --git a/region/templates/region/region_people_page.html b/region/templates/region/region_people_page.html index 49cad809f..4e9aa4e6a 100644 --- a/region/templates/region/region_people_page.html +++ b/region/templates/region/region_people_page.html @@ -12,8 +12,8 @@ <h2 class="head-heavy-base mb-4">Členové a příznivci</h2> <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 row-gap-8 col-gap-8"> - {% for person in people %} - {% include "shared/person_badge_snippet.html" with person=person %} + {% for person_page in people %} + {% include "shared/person_badge_snippet.html" %} {% endfor %} </div> diff --git a/region/templates/region/region_person_page.html b/region/templates/region/region_person_page.html index 13cde222a..4107dbd8e 100644 --- a/region/templates/region/region_person_page.html +++ b/region/templates/region/region_person_page.html @@ -77,8 +77,8 @@ </div> <div class="space-y-4"> - {% for person in random_people %} - {% include "shared/person_badge_snippet.html" with person=person skipcontacts=1 %} + {% for person_page in random_people %} + {% include "shared/person_badge_snippet.html" with person_page=person skipcontacts=1 %} {% endfor %} </div> diff --git a/shared/templates/shared/person_badge_snippet.html b/shared/templates/shared/person_badge_snippet.html index b21facb8f..6f53bc192 100644 --- a/shared/templates/shared/person_badge_snippet.html +++ b/shared/templates/shared/person_badge_snippet.html @@ -1,36 +1,38 @@ {% load wagtailimages_tags %} <div class="badge "> - <a href="{{ person.url }}" class="avatar badge__avatar avatar--sm"> - {% image person.profile_photo max-80x80 as profile_img %} - <img src="{% firstof person.person.portrait profile_img.url %}" alt="{{ person.person.name }}"/> + <a href="{{ person_page.url }}" class="avatar badge__avatar avatar--sm"> + {% image person_page.profile_photo max-80x80 as profile_img %} + <img src="{% firstof person_page.person.portrait profile_img.url %}" alt="{{ person_page.person.name }}"/> </a> <div class="badge__body"> <h2 class="head-heavy-xs badge__title"> - <a href="{{ person.url }}" title="{{ person.person.name }}" class="content-block--nostyle"> - {{ person.person.name }} + <a href="{{ person_page.url }}" title="{{ person_page.person.name }}" class="content-block--nostyle"> + {{ person_page.person.name }} </a> </h2> <p class="badge__occupation"> {% if title %} {{ title }} {% else %} - {{ person.job_function }} + {{ person_page.job_function }} {% endif %} </p> {% if not skipcontacts %} - {% if person.person.phone %} - <a href="tel:person.person.phone" + {% if person_page.get_phone %} + <a href="tel:{{ person_page.get_phone }}" class="contact-line icon-link content-block--nostyle contact-line--responsive badge__link"> <i class="ico--phone"></i> - <span>{{ person.person.phone }}</span> + <span>{{ person_page.get_phone }}</span> + </a> + {% endif %} + {% if person_page.get_email %} + <a href="mailto:{{ person_page.get_email }}" + class="contact-line icon-link content-block--nostyle contact-line--responsive badge__link"> + <i class="ico--envelope"></i><span>{{ person_page.get_email }}</span> </a> {% endif %} - <a href="mailto:{{ person.person.email }}" - class="contact-line icon-link content-block--nostyle contact-line--responsive badge__link"> - <i class="ico--envelope"></i><span>{{ person.person.email }}</span> - </a> {% endif %} </div> </div> -- GitLab