From f5c07140b75ea1a46357a19874c6c8236f144b3f Mon Sep 17 00:00:00 2001 From: "jindra12.underdark" <jindra12.underdark@gmail.com> Date: Mon, 10 Apr 2023 13:06:49 +0200 Subject: [PATCH] Add support for generic links in events location in calendar Also, add overflow-auto to markdown event descriptions #181 --- calendar_utils/models.py | 8 ++++++++ .../templates/shared/calendar_current_events_snippet.html | 7 ++++++- shared/templates/shared/small_calendar_snippet.html | 7 ++++++- uniweb/templates/uniweb/blocks/calendar_agenda.html | 2 +- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/calendar_utils/models.py b/calendar_utils/models.py index 939e7c02..c733fe7d 100644 --- a/calendar_utils/models.py +++ b/calendar_utils/models.py @@ -3,6 +3,7 @@ from datetime import date, timedelta import arrow from django.core.serializers.json import DjangoJSONEncoder +from django.core.validators import URLValidator from django.db import models from icalevents import icalevents @@ -25,10 +26,17 @@ class EventsJSONField(models.JSONField): def from_db_value(self, value, expression, connection): value = super().from_db_value(value, expression, connection) + urlValidator = URLValidator() if value: for event in value: event["start"] = arrow.get(event.get("start")).datetime event["end"] = arrow.get(event["end"]).datetime + try: + urlValidator(event.get("location")) + event["url"] = event.get("location") + except: + pass + return value diff --git a/shared/templates/shared/calendar_current_events_snippet.html b/shared/templates/shared/calendar_current_events_snippet.html index e16b5a33..da8181a2 100644 --- a/shared/templates/shared/calendar_current_events_snippet.html +++ b/shared/templates/shared/calendar_current_events_snippet.html @@ -32,7 +32,7 @@ {{ event.summary }} </span> {% if event.description %} - <p class="font-light text-sm mt-1"> + <p class="font-light text-sm mt-1 overflow-auto"> {{ event.description | safe }} </p> {% endif %} @@ -44,6 +44,11 @@ <i aria-hidden="true" class="ico--jitsi text-violet-300 mr-1"></i> <span>Jitsi URL</span> </a> + {% elif event.url %} + <a href="{{ event.url }}" class="icon-link"> + <i aria-hidden="true" class="ico--link text-violet-300 mr-1"></i> + <span>Odkaz</span> + </a> {% elif event.location %} <a href="https://maps.google.com/maps?q={{ event.location }}" class="icon-link"> <i aria-hidden="true" class="ico--location text-violet-300 mr-1"></i> diff --git a/shared/templates/shared/small_calendar_snippet.html b/shared/templates/shared/small_calendar_snippet.html index 07a550e1..e0e15409 100644 --- a/shared/templates/shared/small_calendar_snippet.html +++ b/shared/templates/shared/small_calendar_snippet.html @@ -18,7 +18,7 @@ {{ event.summary }} </span> {% if event.description %} - <p class="font-light text-sm mt-1">{{ event.description | safe }}</p> + <p class="font-light text-sm mt-1 overflow-auto">{{ event.description | safe }}</p> {% endif %} </div> </div> @@ -28,6 +28,11 @@ <i aria-hidden="true" class="ico--link text-violet-300 mr-1"></i> <span>Jitsi URL</span> </a> + {% elif event.url %} + <a href="{{ event.url }}" class="icon-link"> + <i aria-hidden="true" class="ico--link text-violet-300 mr-1"></i> + <span>Odkaz</span> + </a> {% elif event.location %} <a href="https://maps.google.com/maps?q={{ event.location }}" class="icon-link"> <i aria-hidden="true" class="ico--location text-violet-300 mr-1"></i> diff --git a/uniweb/templates/uniweb/blocks/calendar_agenda.html b/uniweb/templates/uniweb/blocks/calendar_agenda.html index c45f1caf..7a14074d 100644 --- a/uniweb/templates/uniweb/blocks/calendar_agenda.html +++ b/uniweb/templates/uniweb/blocks/calendar_agenda.html @@ -12,7 +12,7 @@ <div class="col-span-3 md:col-span-2 mt-4 md:mt-0"> <strong class="block">{{ event.summary }}</strong> {% if event.description %} - <p class="font-light text-sm mt-1">{{ event.description }}</p> + <p class="font-light text-sm mt-1 ">{{ event.description }}</p> {% endif %} {% if event.location %} <p class="font-light text-sm mt-1">{{ event.location }}</p> -- GitLab