Skip to content
Snippets Groups Projects
Commit 75638505 authored by Tomáš Valenta's avatar Tomáš Valenta
Browse files

add calendar urls + validation

parent 8a06e6ab
No related branches found
No related tags found
2 merge requests!787Release,!749Add personal calendars, move from requests-cache to Django cache
# Generated by Django 4.1.6 on 2023-04-12 12:06
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('main', '0053_merge_20230406_1446'),
]
operations = [
migrations.AddField(
model_name='mainpersonpage',
name='ical_calendar_url',
field=models.URLField(blank=True, help_text='Musí být ve formátu iCal. V Google kalendáři lze exportovat v nastavení (TODO).', max_length=256, null=True, verbose_name='iCal adresa kalendáře'),
),
migrations.AddField(
model_name='mainpersonpage',
name='nextcloud_calendar_url',
field=models.URLField(blank=True, help_text='V nastavení kalendáře klikni na ikonu "+" vedle "odkaz na sdílení" a vlož zkopírovaný odkaz.', max_length=256, null=True, verbose_name='Adresa kalendáře v Mraku'),
),
]
...@@ -5,6 +5,7 @@ from django.conf import settings ...@@ -5,6 +5,7 @@ from django.conf import settings
from django.contrib import messages from django.contrib import messages
from django.core.paginator import Paginator from django.core.paginator import Paginator
from django.db import models from django.db import models
from django.forms import ValidationError
from django.http import HttpResponseRedirect, JsonResponse from django.http import HttpResponseRedirect, JsonResponse
from django.shortcuts import render from django.shortcuts import render
from django.utils import timezone from django.utils import timezone
...@@ -800,6 +801,23 @@ class MainPersonPage(ExtendedMetadataPageMixin, SubpageMixin, MetadataPageMixin, ...@@ -800,6 +801,23 @@ class MainPersonPage(ExtendedMetadataPageMixin, SubpageMixin, MetadataPageMixin,
email = models.CharField("E-mail", max_length=128, blank=True, null=True) email = models.CharField("E-mail", max_length=128, blank=True, null=True)
phone = models.CharField("Telefonní kontakt", max_length=16, blank=True, null=True) phone = models.CharField("Telefonní kontakt", max_length=16, blank=True, null=True)
ical_calendar_url = models.URLField(
"iCal adresa kalendáře",
max_length=256,
blank=True,
null=True,
help_text="Musí být ve formátu iCal. V Google kalendáři lze exportovat v nastavení (TODO).",
)
nextcloud_calendar_url = models.URLField(
"Adresa kalendáře v Mraku",
max_length=256,
blank=True,
null=True,
help_text=(
'V nastavení kalendáře klikni na ikonu "+" vedle "odkaz na sdílení" '
"a vlož zkopírovaný odkaz."
)
)
settings_panels = [] settings_panels = []
...@@ -820,6 +838,13 @@ class MainPersonPage(ExtendedMetadataPageMixin, SubpageMixin, MetadataPageMixin, ...@@ -820,6 +838,13 @@ class MainPersonPage(ExtendedMetadataPageMixin, SubpageMixin, MetadataPageMixin,
FieldPanel("text"), FieldPanel("text"),
FieldPanel("email"), FieldPanel("email"),
FieldPanel("phone"), FieldPanel("phone"),
MultiFieldPanel(
[
FieldPanel("ical_calendar_url"),
FieldPanel("nextcloud_calendar_url"),
],
"Kalendář",
),
FieldPanel("social_links"), FieldPanel("social_links"),
FieldPanel("people"), FieldPanel("people"),
] ]
...@@ -845,6 +870,28 @@ class MainPersonPage(ExtendedMetadataPageMixin, SubpageMixin, MetadataPageMixin, ...@@ -845,6 +870,28 @@ class MainPersonPage(ExtendedMetadataPageMixin, SubpageMixin, MetadataPageMixin,
### OTHERS ### OTHERS
def clean(self) -> None:
cleaned_data = super().clean()
BOTH_CALENDARS_DEFINED_ERROR_MESSAGE = (
"Nemůžeš definovat kalendář z Mraku a v iCal formátu najednou."
)
if (
cleaned_data.get("ical_calendar_url")
and cleaned_data.get("nextcloud_calendar_url")
):
self.add_error(
"ical_calendar_url",
BOTH_CALENDARS_DEFINED_ERROR_MESSAGE
)
self.add_error(
"nextcloud_calendar_url",
BOTH_CALENDARS_DEFINED_ERROR_MESSAGE
)
return cleaned_data
class Meta: class Meta:
verbose_name = "Detail osoby" verbose_name = "Detail osoby"
# ordering = ("title",) # ordering = ("title",)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment