Skip to content
Snippets Groups Projects
Commit e546c923 authored by jan.bednarik's avatar jan.bednarik
Browse files

calendar utils: Handle wrong calendars

parent 734b571b
No related branches found
No related tags found
2 merge requests!627calendar utils: Handle wrong calendars,!626calendar utils: Handle wrong calendars
Pipeline #9817 passed
import logging
from django.core.management.base import BaseCommand
from ...models import Calendar
logger = logging.getLogger(__name__)
class Command(BaseCommand):
def handle(self, *args, **options):
......@@ -12,7 +16,7 @@ class Command(BaseCommand):
cal.update_source()
self.stdout.write("+ ok")
except Exception as e:
# TODO logging
logger.error("Calendar update failed for %s", cal.url, exc_info=True)
self.stdout.write("- failed")
self.stdout.write(str(e))
......
import logging
from datetime import date, timedelta
import arrow
......@@ -7,6 +8,8 @@ from icalevnt import icalevents
from .parser import process_event_list
logger = logging.getLogger(__name__)
def _convert_arrow_to_datetime(event):
event["start"] = event["start"].datetime
......@@ -86,11 +89,18 @@ class CalendarMixin(models.Model):
self.calendar.save()
else:
self.calendar = Calendar.objects.create(url=self.calendar_url)
self.calendar.update_source()
try:
self.calendar.update_source()
except:
logger.error(
"Calendar update failed for %s", self.calendar.url, exc_info=True
)
# delete related Calendar when URL is cleared
if not self.calendar_url and self.calendar:
self.calendar.delete()
# TODO handle revisions and maybe other live pages with the same calendar
# self.calendar.delete()
self.calendar = None
super().save(*args, **kwargs)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment