diff --git a/district/migrations/0012_auto_20211118_0818.py b/district/migrations/0012_auto_20211118_0818.py new file mode 100644 index 0000000000000000000000000000000000000000..740c790cb7d422049564ceeaf25169f3de41ae14 --- /dev/null +++ b/district/migrations/0012_auto_20211118_0818.py @@ -0,0 +1,65 @@ +# Generated by Django 3.2.8 on 2021-11-18 07:18 + +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("wagtailimages", "0023_add_choose_permissions"), + ("district", "0011_auto_20211117_2136"), + ] + + operations = [ + migrations.AddField( + model_name="districtpersonpage", + name="background_photo", + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.PROTECT, + related_name="+", + to="wagtailimages.image", + ), + ), + migrations.AddField( + model_name="districtpersonpage", + name="email", + field=models.EmailField( + blank=True, max_length=254, null=True, verbose_name="Email" + ), + ), + migrations.AddField( + model_name="districtpersonpage", + name="is_pirate", + field=models.BooleanField( + default=True, verbose_name="Je členem Pirátské strany?" + ), + ), + migrations.AddField( + model_name="districtpersonpage", + name="job", + field=models.CharField( + blank=True, max_length=64, null=True, verbose_name="Povolání/pozice" + ), + ), + migrations.AddField( + model_name="districtpersonpage", + name="phone", + field=models.EmailField( + blank=True, max_length=254, null=True, verbose_name="Telefon" + ), + ), + migrations.AddField( + model_name="districtpersonpage", + name="profile_photo", + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.PROTECT, + related_name="+", + to="wagtailimages.image", + ), + ), + ] diff --git a/district/migrations/0013_auto_20211118_0824.py b/district/migrations/0013_auto_20211118_0824.py new file mode 100644 index 0000000000000000000000000000000000000000..2b2f3293be9eadac66844979a82784f64312b58f --- /dev/null +++ b/district/migrations/0013_auto_20211118_0824.py @@ -0,0 +1,42 @@ +# Generated by Django 3.2.8 on 2021-11-18 07:24 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("district", "0012_auto_20211118_0818"), + ] + + operations = [ + migrations.AddField( + model_name="districtpersonpage", + name="job_function", + field=models.CharField( + blank=True, + help_text="Např. 'Předseda'", + max_length=64, + null=True, + verbose_name="Funkce", + ), + ), + migrations.AlterField( + model_name="districtpersonpage", + name="job", + field=models.CharField( + blank=True, + help_text="Např. 'Informatik'", + max_length=64, + null=True, + verbose_name="Povolání", + ), + ), + migrations.AlterField( + model_name="districtpersonpage", + name="phone", + field=models.CharField( + blank=True, max_length=16, null=True, verbose_name="Telefon" + ), + ), + ] diff --git a/district/migrations/0014_districthomepage_fallback_image.py b/district/migrations/0014_districthomepage_fallback_image.py new file mode 100644 index 0000000000000000000000000000000000000000..edffc5b0d09cfd49ff1df33e59781cf05c1a3850 --- /dev/null +++ b/district/migrations/0014_districthomepage_fallback_image.py @@ -0,0 +1,25 @@ +# Generated by Django 3.2.8 on 2021-11-18 07:35 + +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("wagtailimages", "0023_add_choose_permissions"), + ("district", "0013_auto_20211118_0824"), + ] + + operations = [ + migrations.AddField( + model_name="districthomepage", + name="fallback_image", + field=models.ForeignKey( + null=True, + on_delete=django.db.models.deletion.PROTECT, + related_name="+", + to="wagtailimages.image", + ), + ), + ] diff --git a/district/models.py b/district/models.py index 2d180d72253b0680f61ebd651c96d8538c23a636..b0e965dc5345fb30d15ccf9b70cfa7ab8d805274 100644 --- a/district/models.py +++ b/district/models.py @@ -15,6 +15,7 @@ from wagtail.admin.edit_handlers import ( from wagtail.core import blocks from wagtail.core.fields import RichTextField, StreamField from wagtail.core.models import Page +from wagtail.images.edit_handlers import ImageChooserPanel from wagtailmetadata.models import MetadataPageMixin from calendar_utils.models import CalendarMixin @@ -89,6 +90,12 @@ class DistrictHomePage(MetadataPageMixin, CalendarMixin, Page): matomo_id = models.IntegerField( "Matomo ID pro sledování návštěvnosti", blank=True, null=True ) + fallback_image = models.ForeignKey( + "wagtailimages.Image", + on_delete=models.PROTECT, + null=True, + related_name="+", + ) ### PANELS @@ -136,6 +143,7 @@ class DistrictHomePage(MetadataPageMixin, CalendarMixin, Page): ], gettext_lazy("Nastavení lišty s kalendářem a mapou"), ), + ImageChooserPanel("fallback_image"), CommentPanel(), ] @@ -388,10 +396,35 @@ class DistrictPersonTag(TaggedItemBase): class DistrictPersonPage(SubpageMixin, MetadataPageMixin, Page): ### FIELDS + job = models.CharField( + "Povolání", max_length=64, blank=True, null=True, help_text="Např. 'Informatik'" + ) + job_function = models.CharField( + "Funkce", max_length=64, blank=True, null=True, help_text="Např. 'Předseda'" + ) perex = models.TextField("Perex osoby", blank=True) + background_photo = models.ForeignKey( + "wagtailimages.Image", + on_delete=models.PROTECT, + blank=True, + null=True, + related_name="+", + ) + profile_photo = models.ForeignKey( + "wagtailimages.Image", + on_delete=models.PROTECT, + blank=True, + null=True, + related_name="+", + ) person = models.ForeignKey(Person, on_delete=models.PROTECT, null=True) text = RichTextField("text", blank=True, features=RICH_TEXT_FEATURES) + # Fallbackové hodnoty pro data získávana z API (viz Person model) + email = models.EmailField("Email", blank=True, null=True) + phone = models.CharField("Telefon", max_length=16, blank=True, null=True) + is_pirate = models.BooleanField("Je členem Pirátské strany?", default=True) + facebook_url = models.URLField("Odkaz na Facebook", blank=True, null=True) instagram_url = models.URLField("Odkaz na Instagram", blank=True, null=True) twitter_url = models.URLField("Odkaz na Twitter", blank=True, null=True) @@ -402,16 +435,33 @@ class DistrictPersonPage(SubpageMixin, MetadataPageMixin, Page): content_panels = Page.content_panels + [ FieldPanel("person"), + FieldPanel("job"), + FieldPanel("job_function"), + ImageChooserPanel("background_photo"), + ImageChooserPanel("profile_photo"), FieldPanel("perex"), FieldPanel("text"), ] settings_panels = [ - FieldPanel("facebook_url"), - FieldPanel("instagram_url"), - FieldPanel("twitter_url"), - FieldPanel("youtube_url"), - FieldPanel("flickr_url"), + MultiFieldPanel( + [ + FieldPanel("email"), + FieldPanel("phone"), + FieldPanel("is_pirate"), + ], + "Kontaktní informace", + ), + MultiFieldPanel( + [ + FieldPanel("facebook_url"), + FieldPanel("instagram_url"), + FieldPanel("twitter_url"), + FieldPanel("youtube_url"), + FieldPanel("flickr_url"), + ], + "Sociální sítě", + ), ] ### RELATIONS @@ -424,6 +474,17 @@ class DistrictPersonPage(SubpageMixin, MetadataPageMixin, Page): class Meta: verbose_name = "Detail osoby" + def get_background_photo(self): + """ + Vrací background_photo pro pozadí na stránce, pokud není nastaveno, + vezme falbback z homepage + """ + return ( + self.background_photo + if self.background_photo + else self.root_page.fallback_image + ) + @property def pageperex(self): """ diff --git a/district/templates/district/district_person_page.html b/district/templates/district/district_person_page.html index 3fa8aca63c612797fb303b943b03fcf72676fe1c..c2abb8506dbb165f189d2684b43f71dec096640b 100644 --- a/district/templates/district/district_person_page.html +++ b/district/templates/district/district_person_page.html @@ -2,15 +2,20 @@ {% load wagtailcore_tags wagtailimages_tags shared_filters %} {% block subheader %} + {% image page.get_background_photo width-1920 as bg_img %} <header class="hero hero--image pt-16 pb-24 lg:pt-32 pb-24 candidate-detail__hero" - style="--image-url: url(https://roznov.pirati.cz/assets/articles/2020/kampan20/zahajenikampan1-067fb446ec8933ae14591cbc29fc53ebb3009e4185900838bfb94752addbfa7b.jpg)" + style="--image-url: url({{ bg_img.url }})" > <div class="container container--default py-2"> <h1 class="head-alt-md md:head-alt-lg max-w-2xl text-left lg:text-left px-4"> - <span class="academic-title-name">{{ page.name }}</span> + <span class="academic-title-name"> + {{ page.title }} + </span> </h1> - <h2 class="head-xs mt-2 max-w-xl mx-auto text-center lg:text-left"></h2> + <h2 class="head-xs mt-2 max-w-xl mx-auto text-center lg:text-left"> + {{ page.job }} + </h2> </div> </header> {% endblock %} @@ -30,7 +35,8 @@ <div class="card__body p-4 lg:p-8"> <div class="text-center mb-8"> <div class="avatar avatar--2xl lg:avatar--3xl avatar--bordered candidate-detail__avatar"> - <img src="http://placeimg.com/100/100/people" alt="Avatar"> + {% image page.profile_photo max-208x208 as profile_img %} + <img src="{{ profile_img.url }}" alt="Avatar"> </div> </div> @@ -71,13 +77,15 @@ </a> </div> {% endif %} - <div> - <h4>Email</h4> - <a href="mailto:{{ page.email }}" class="contact-line icon-link content-block--nostyle "> - <i class="ico--envelope"></i><span>{{ page.email }}</span> - </a> + {% if page.phone %} + <div> + <h4>Email</h4> + <a href="mailto:{{ page.email }}" class="contact-line icon-link content-block--nostyle "> + <i class="ico--envelope"></i><span>{{ page.email }}</span> + </a> + </div> + {% endif %} </div> - </div> <hr> <h2>Lidé</h2> diff --git a/shared/templates/shared/person_badge_snippet.html b/shared/templates/shared/person_badge_snippet.html index 961dc77f5d45a318e9ca7040fd470c5c72c0ff92..b21facb8f53b32be331289610074e276bc69ebee 100644 --- a/shared/templates/shared/person_badge_snippet.html +++ b/shared/templates/shared/person_badge_snippet.html @@ -1,34 +1,36 @@ +{% load wagtailimages_tags %} - <div class="badge "> +<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> - <a href="{{ person.url }}" class="avatar badge__avatar avatar--sm"> - <img src="{{ person.person.portrait }}" alt="{{ person.person.name }}" /> + <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> - - <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> - </h2> - <p class="badge__occupation"> - {% if title %} - {{ title }} - {% else %} - {{ person.pageperex|linebreaksbr }} - {% endif %} - </p> - {% if not skipcontacts %} - {% if person.person.phone %} - <a href="tel:person.person.phone" class="contact-line icon-link content-block--nostyle contact-line--responsive badge__link" > - <i class="ico--phone"></i> - <span>{{ person.person.phone }}</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> + </h2> + <p class="badge__occupation"> + {% if title %} + {{ title }} + {% else %} + {{ person.job_function }} + {% endif %} + </p> + {% if not skipcontacts %} + {% if person.person.phone %} + <a href="tel:person.person.phone" + class="contact-line icon-link content-block--nostyle contact-line--responsive badge__link"> + <i class="ico--phone"></i> + <span>{{ person.person.phone }}</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>