Skip to content
Snippets Groups Projects
Verified Commit 409fbc99 authored by Jonathan Weth's avatar Jonathan Weth :keyboard:
Browse files

Add import code for holidays

parent 52f3d140
No related branches found
No related tags found
1 merge request!13Resolve "Support import from MySQL"
......@@ -87,3 +87,8 @@ chronos_models.Event.field(
verbose_name=_("UNTIS import reference"), null=True, blank=True
)
)
chronos_models.Holiday.field(
import_ref_untis=IntegerField(
verbose_name=_("UNTIS import reference"), null=True, blank=True
)
)
import logging
from typing import Dict
from aleksis.apps.chronos import models as chronos_models
from .... import models as mysql_models
from ..util import run_default_filter, untis_date_to_date
logger = logging.getLogger(__name__)
def import_holidays() -> Dict[int, chronos_models.Holiday]:
""" Import holidays """
ref = {}
# Get holidays
holidays = run_default_filter(mysql_models.Holiday.objects, filter_term=False)
for holiday in holidays:
import_ref = holiday.holiday_id
# Check if needed data are provided
if not holiday.name:
logger.error(
"Holiday ID {}: Cannot import holiday without short name.".format(
import_ref
)
)
continue
title = holiday.name[:50]
comments = holiday.longname
date_start = untis_date_to_date(holiday.datefrom)
date_end = untis_date_to_date(holiday.dateto)
logger.info("Import holiday {} …".format(title))
# Get or create holiday
new_holiday, created = chronos_models.Holiday.objects.get_or_create(
import_ref_untis=import_ref,
defaults={
"title": title,
"comments": comments,
"date_start": date_start,
"date_end": date_end
}
)
if created:
logger.info(" New holiday created")
if (
new_holiday.title != title
or new_holiday.comments != comments
or new_holiday.date_start != date_start
or new_holiday.date_end != date_end
):
new_holiday.title = title
new_holiday.comments = comments
new_holiday.date_start = date_start
new_holiday.date_end = date_end
new_holiday.save()
logger.info(" Holiday updated")
ref[import_ref] = new_holiday
return ref
......@@ -10,6 +10,7 @@ from .importers.common_data import (
import_absence_reasons,
)
from .importers.events import import_events
from .importers.holidays import import_holidays
from .importers.lessons import import_lessons
from .importers.substitutions import import_substitutions
......@@ -28,6 +29,9 @@ def untis_import_mysql():
time_periods_ref = import_time_periods()
breaks_ref = import_breaks(time_periods_ref)
# Holidays
holidays_ref = import_holidays()
# Supervisions
supervision_areas_ref = import_supervision_areas(breaks_ref, teachers_ref)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment