From f6520d6981dd6a85729a8f1886b810553d4439ba Mon Sep 17 00:00:00 2001 From: xaralis <filip.varecha@fragaria.cz> Date: Fri, 6 May 2022 12:31:11 +0200 Subject: [PATCH] feat(district): support candidates from other parties --- ...districtpersonpage_other_party_and_more.py | 39 +++++++++++++++++++ district/models.py | 18 +++++++++ .../district/district_person_page.html | 13 +++++++ .../shared/compact_candidate_snippet.html | 13 ++++++- .../shared/full_candidate_snippet.html | 13 ++++++- 5 files changed, 92 insertions(+), 4 deletions(-) create mode 100644 district/migrations/0069_districtpersonpage_other_party_and_more.py diff --git a/district/migrations/0069_districtpersonpage_other_party_and_more.py b/district/migrations/0069_districtpersonpage_other_party_and_more.py new file mode 100644 index 00000000..dca35c78 --- /dev/null +++ b/district/migrations/0069_districtpersonpage_other_party_and_more.py @@ -0,0 +1,39 @@ +# Generated by Django 4.0.3 on 2022-05-06 09:49 + +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("wagtailimages", "0023_add_choose_permissions"), + ("district", "0068_districtelectioncampaignpage_and_more"), + ] + + operations = [ + migrations.AddField( + model_name="districtpersonpage", + name="other_party", + field=models.CharField( + blank=True, + help_text="Vyplňte pokud osoba není Pirát", + max_length=64, + null=True, + verbose_name="Strana", + ), + ), + migrations.AddField( + model_name="districtpersonpage", + name="other_party_logo", + field=models.ForeignKey( + blank=True, + help_text="Vyplňte pokud osoba není Pirát", + null=True, + on_delete=django.db.models.deletion.PROTECT, + related_name="+", + to="wagtailimages.image", + verbose_name="Logo strany", + ), + ), + ] diff --git a/district/models.py b/district/models.py index 980ae727..237f504f 100644 --- a/district/models.py +++ b/district/models.py @@ -661,6 +661,22 @@ class DistrictPersonPage( city = models.CharField("Město/obec", max_length=64, blank=True, null=True) age = models.IntegerField("Věk", blank=True, null=True) is_pirate = models.BooleanField("Je členem Pirátské strany?", default=True) + other_party = models.CharField( + "Strana", + max_length=64, + blank=True, + null=True, + help_text="Vyplňte pokud osoba není Pirát", + ) + other_party_logo = models.ForeignKey( + "wagtailimages.Image", + on_delete=models.PROTECT, + blank=True, + null=True, + related_name="+", + verbose_name="Logo strany", + help_text="Vyplňte pokud osoba není Pirát", + ) facebook_url = models.URLField("Odkaz na Facebook", blank=True, null=True) instagram_url = models.URLField("Odkaz na Instagram", blank=True, null=True) @@ -700,6 +716,8 @@ class DistrictPersonPage( FieldPanel("city"), FieldPanel("age"), FieldPanel("is_pirate"), + FieldPanel("other_party"), + ImageChooserPanel("other_party_logo"), ], "Kontaktní informace", ), diff --git a/district/templates/district/district_person_page.html b/district/templates/district/district_person_page.html index ce271ea0..fc50c254 100644 --- a/district/templates/district/district_person_page.html +++ b/district/templates/district/district_person_page.html @@ -90,6 +90,19 @@ </div> {% endif %} + {% if not page.is_pirate and page.other_party %} + <hr> + <div class="flex items-center"> + {% if page.other_party_logo %} + {% image page.other_party_logo width-48 as logo_img %} + <div class="avatar w-6 mr-2"> + <img src="{{ logo_img.url }}" alt="{{ page.other_party }}"> + </div> + {% endif %} + <span class="font-bold font-condensed">{{ page.other_party }}</span> + </div> + {% endif %} + {% if page.phone or page.email and page.show_email %} <hr> <div class="content-block"> diff --git a/shared/templates/shared/compact_candidate_snippet.html b/shared/templates/shared/compact_candidate_snippet.html index 8891ab4c..2cb6100b 100644 --- a/shared/templates/shared/compact_candidate_snippet.html +++ b/shared/templates/shared/compact_candidate_snippet.html @@ -25,8 +25,17 @@ <img src="{% static "shared/img/logo_black.svg" %}" alt="Pirátská strana"> </div> <span class="font-bold font-condensed">Pirátská strana</span> - {% else %} - <span class="font-bold font-condensed">bez politické příslušnosti</span> + {% endif %} + + {% if not person_page.is_pirate and person_page.other_party %} + {% if person_page.other_party_logo %} + {% image person_page.other_party_logo width-48 as logo_img %} + <div class="avatar w-6 mr-2"> + <img src="{{ logo_img.url }}" alt="{{ person_page.other_party }}"> + </div> + {% endif %} + + <span class="font-bold font-condensed">{{ person_page.other_party }}</span> {% endif %} </div> </div> diff --git a/shared/templates/shared/full_candidate_snippet.html b/shared/templates/shared/full_candidate_snippet.html index 00eca3e2..e924069b 100644 --- a/shared/templates/shared/full_candidate_snippet.html +++ b/shared/templates/shared/full_candidate_snippet.html @@ -44,8 +44,17 @@ <img src="{% static "shared/img/logo_black.svg" %}" alt="Pirátská strana"> </div> <span class="font-bold font-condensed">Pirátská strana</span> - {% else %} - <span class="font-bold font-condensed">bez politické příslušnosti</span> + {% endif %} + + {% if not person_page.is_pirate and person_page.other_party %} + {% if person_page.other_party_logo %} + {% image person_page.other_party_logo width-48 as logo_img %} + <div class="avatar w-6 mr-2"> + <img src="{{ logo_img.url }}" alt="{{ person_page.other_party }}"> + </div> + {% endif %} + + <span class="font-bold font-condensed">{{ person_page.other_party }}</span> {% endif %} </div> </div> -- GitLab