Skip to content
Snippets Groups Projects
Commit 8039a944 authored by Štěpán Farka's avatar Štěpán Farka
Browse files

[ADD] unique email per people page, show email boolean, required email

parent df8a333d
Branches
No related tags found
2 merge requests!435Release upgrades,!430Feature/majak misc enhancements
Pipeline #7204 passed
# Generated by Django 3.2.11 on 2022-03-09 12:19
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("district", "0041_auto_20220309_1109"),
]
operations = [
migrations.AddField(
model_name="districtpersonpage",
name="show_email",
field=models.BooleanField(
default=True, verbose_name="Zobrazovat email na stránce?"
),
),
migrations.AlterField(
model_name="districtpersonpage",
name="email",
field=models.EmailField(max_length=254, null=True, verbose_name="Email"),
),
]
import random import random
from django.core.exceptions import ValidationError
from django.core.paginator import Paginator from django.core.paginator import Paginator
from django.db import models from django.db import models
from django.shortcuts import render from django.shortcuts import render
...@@ -16,6 +17,7 @@ from wagtail.admin.edit_handlers import ( ...@@ -16,6 +17,7 @@ from wagtail.admin.edit_handlers import (
StreamFieldPanel, StreamFieldPanel,
TabbedInterface, TabbedInterface,
) )
from wagtail.admin.forms import WagtailAdminPageForm
from wagtail.contrib.table_block.blocks import TableBlock from wagtail.contrib.table_block.blocks import TableBlock
from wagtail.core.blocks import RichTextBlock from wagtail.core.blocks import RichTextBlock
from wagtail.core.fields import RichTextField, StreamField from wagtail.core.fields import RichTextField, StreamField
...@@ -434,8 +436,23 @@ class DistrictPersonTag(TaggedItemBase): ...@@ -434,8 +436,23 @@ class DistrictPersonTag(TaggedItemBase):
) )
class DistrictPersonPageForm(WagtailAdminPageForm):
def clean(self):
cleaned_data = super().clean()
email = cleaned_data.get("email", None)
if email:
pages_with_email = DistrictPersonPage.objects.filter(email=email)
num_pages_with_email = len(pages_with_email)
if num_pages_with_email > 1 or (
num_pages_with_email == 1 and pages_with_email[0] != self.instance
):
raise ValidationError({"email": "Stránka s tímto emailem již existuje"})
return cleaned_data
class DistrictPersonPage(SubpageMixin, MetadataPageMixin, Page): class DistrictPersonPage(SubpageMixin, MetadataPageMixin, Page):
### FIELDS ### FIELDS
base_form_class = DistrictPersonPageForm
job = models.CharField( job = models.CharField(
"Povolání", "Povolání",
...@@ -465,7 +482,8 @@ class DistrictPersonPage(SubpageMixin, MetadataPageMixin, Page): ...@@ -465,7 +482,8 @@ class DistrictPersonPage(SubpageMixin, MetadataPageMixin, Page):
) )
text = RichTextField("text", blank=True, features=RICH_TEXT_FEATURES) text = RichTextField("text", blank=True, features=RICH_TEXT_FEATURES)
email = models.EmailField("Email", blank=True, null=True) email = models.EmailField("Email", null=True)
show_email = models.BooleanField("Zobrazovat email na stránce?", default=True)
phone = models.CharField("Telefon", max_length=16, blank=True, null=True) phone = models.CharField("Telefon", max_length=16, blank=True, null=True)
city = models.CharField("Město/obec", max_length=64, blank=True, null=True) city = models.CharField("Město/obec", max_length=64, blank=True, null=True)
age = models.IntegerField("Věk", blank=True, null=True) age = models.IntegerField("Věk", blank=True, null=True)
...@@ -504,6 +522,7 @@ class DistrictPersonPage(SubpageMixin, MetadataPageMixin, Page): ...@@ -504,6 +522,7 @@ class DistrictPersonPage(SubpageMixin, MetadataPageMixin, Page):
MultiFieldPanel( MultiFieldPanel(
[ [
FieldPanel("email"), FieldPanel("email"),
FieldPanel("show_email"),
FieldPanel("phone"), FieldPanel("phone"),
FieldPanel("city"), FieldPanel("city"),
FieldPanel("age"), FieldPanel("age"),
......
...@@ -90,6 +90,7 @@ ...@@ -90,6 +90,7 @@
{# </div>#} {# </div>#}
<hr> <hr>
<div class="content-block"> <div class="content-block">
{% if page.phone or page.email and page.show_email %}
<div class="space-y-4"> <div class="space-y-4">
{% if page.phone %} {% if page.phone %}
<div> <div>
...@@ -99,16 +100,18 @@ ...@@ -99,16 +100,18 @@
</a> </a>
</div> </div>
{% endif %} {% endif %}
{% if page.phone %} {% if page.email and page.show_email %}
<div> <div>
<h4>Email</h4> <h4>Email</h4>
<a href="mailto:{{ page.email }}" class="contact-line icon-link content-block--nostyle "> <a href="mailto:{{ page.email }}"
class="contact-line icon-link content-block--nostyle ">
<i class="ico--envelope"></i><span>{{ page.email }}</span> <i class="ico--envelope"></i><span>{{ page.email }}</span>
</a> </a>
</div> </div>
{% endif %} {% endif %}
</div> </div>
<hr> <hr>
{% endif %}
<h2>Lidé</h2> <h2>Lidé</h2>
<div class="space-y-4 mt-4"> <div class="space-y-4 mt-4">
......
# Generated by Django 3.2.11 on 2022-03-09 12:57
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("region", "0016_auto_20220309_1109"),
]
operations = [
migrations.AddField(
model_name="regionpersonpage",
name="show_email",
field=models.BooleanField(
default=True, verbose_name="Zobrazovat email na stránce?"
),
),
migrations.AlterField(
model_name="regionpersonpage",
name="email",
field=models.EmailField(max_length=254, null=True, verbose_name="Email"),
),
]
import random import random
from django.core.exceptions import ValidationError
from django.core.paginator import Paginator from django.core.paginator import Paginator
from django.db import models from django.db import models
from django.shortcuts import render from django.shortcuts import render
...@@ -16,6 +17,7 @@ from wagtail.admin.edit_handlers import ( ...@@ -16,6 +17,7 @@ from wagtail.admin.edit_handlers import (
StreamFieldPanel, StreamFieldPanel,
TabbedInterface, TabbedInterface,
) )
from wagtail.admin.forms import WagtailAdminPageForm
from wagtail.contrib.table_block.blocks import TableBlock from wagtail.contrib.table_block.blocks import TableBlock
from wagtail.core.blocks import RichTextBlock from wagtail.core.blocks import RichTextBlock
from wagtail.core.fields import RichTextField, StreamField from wagtail.core.fields import RichTextField, StreamField
...@@ -427,7 +429,22 @@ class RegionPersonTag(TaggedItemBase): ...@@ -427,7 +429,22 @@ class RegionPersonTag(TaggedItemBase):
content_object = ParentalKey("region.RegionPersonPage", on_delete=models.CASCADE) content_object = ParentalKey("region.RegionPersonPage", on_delete=models.CASCADE)
class RegionPersonPageForm(WagtailAdminPageForm):
def clean(self):
cleaned_data = super().clean()
email = cleaned_data.get("email", None)
if email:
pages_with_email = RegionPersonPage.objects.filter(email=email)
num_pages_with_email = len(pages_with_email)
if num_pages_with_email > 1 or (
num_pages_with_email == 1 and pages_with_email[0] != self.instance
):
raise ValidationError({"email": "Stránka s tímto emailem již existuje"})
return cleaned_data
class RegionPersonPage(SubpageMixin, MetadataPageMixin, Page): class RegionPersonPage(SubpageMixin, MetadataPageMixin, Page):
base_form_class = RegionPersonPageForm
### FIELDS ### FIELDS
job = models.CharField( job = models.CharField(
...@@ -458,7 +475,8 @@ class RegionPersonPage(SubpageMixin, MetadataPageMixin, Page): ...@@ -458,7 +475,8 @@ class RegionPersonPage(SubpageMixin, MetadataPageMixin, Page):
) )
text = RichTextField("text", blank=True, features=RICH_TEXT_FEATURES) text = RichTextField("text", blank=True, features=RICH_TEXT_FEATURES)
email = models.EmailField("Email", blank=True, null=True) email = models.EmailField("Email", null=True)
show_email = models.BooleanField("Zobrazovat email na stránce?", default=True)
phone = models.CharField("Telefon", max_length=16, blank=True, null=True) phone = models.CharField("Telefon", max_length=16, blank=True, null=True)
city = models.CharField("Město/obec", max_length=64, blank=True, null=True) city = models.CharField("Město/obec", max_length=64, blank=True, null=True)
age = models.IntegerField("Věk", blank=True, null=True) age = models.IntegerField("Věk", blank=True, null=True)
...@@ -497,6 +515,7 @@ class RegionPersonPage(SubpageMixin, MetadataPageMixin, Page): ...@@ -497,6 +515,7 @@ class RegionPersonPage(SubpageMixin, MetadataPageMixin, Page):
MultiFieldPanel( MultiFieldPanel(
[ [
FieldPanel("email"), FieldPanel("email"),
FieldPanel("show_email"),
FieldPanel("phone"), FieldPanel("phone"),
FieldPanel("city"), FieldPanel("city"),
FieldPanel("age"), FieldPanel("age"),
......
...@@ -95,6 +95,7 @@ ...@@ -95,6 +95,7 @@
{# </div>#} {# </div>#}
<hr> <hr>
<div class="content-block"> <div class="content-block">
{% if page.phone or page.email and page.show_email %}
<div class="space-y-4"> <div class="space-y-4">
{% if page.phone %} {% if page.phone %}
<div> <div>
...@@ -104,16 +105,18 @@ ...@@ -104,16 +105,18 @@
</a> </a>
</div> </div>
{% endif %} {% endif %}
{% if page.phone %} {% if page.email and page.show_email %}
<div> <div>
<h4>Email</h4> <h4>Email</h4>
<a href="mailto:{{ page.email }}" class="contact-line icon-link content-block--nostyle "> <a href="mailto:{{ page.email }}"
class="contact-line icon-link content-block--nostyle ">
<i class="ico--envelope"></i><span>{{ page.email }}</span> <i class="ico--envelope"></i><span>{{ page.email }}</span>
</a> </a>
</div> </div>
{% endif %} {% endif %}
</div> </div>
<hr> <hr>
{% endif %}
<h2>Lidé</h2> <h2>Lidé</h2>
<div class="space-y-4 mt-4"> <div class="space-y-4 mt-4">
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment