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

add calendar urls + validation

parent 8a06e6ab
Branches
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
from django.contrib import messages
from django.core.paginator import Paginator
from django.db import models
from django.forms import ValidationError
from django.http import HttpResponseRedirect, JsonResponse
from django.shortcuts import render
from django.utils import timezone
......@@ -800,6 +801,23 @@ class MainPersonPage(ExtendedMetadataPageMixin, SubpageMixin, MetadataPageMixin,
email = models.CharField("E-mail", max_length=128, 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 = []
......@@ -820,6 +838,13 @@ class MainPersonPage(ExtendedMetadataPageMixin, SubpageMixin, MetadataPageMixin,
FieldPanel("text"),
FieldPanel("email"),
FieldPanel("phone"),
MultiFieldPanel(
[
FieldPanel("ical_calendar_url"),
FieldPanel("nextcloud_calendar_url"),
],
"Kalendář",
),
FieldPanel("social_links"),
FieldPanel("people"),
]
......@@ -845,6 +870,28 @@ class MainPersonPage(ExtendedMetadataPageMixin, SubpageMixin, MetadataPageMixin,
### 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:
verbose_name = "Detail osoby"
# ordering = ("title",)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment