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

Support intersecting terms

parent 255f9d0a
No related branches found
No related tags found
1 merge request!161Resolve "Support overlapping terms"
Pipeline #101222 passed with warnings
......@@ -14,6 +14,7 @@ Fixed
* Importer failed sometimes on progressing absences.
* Exam import failed sometimes when data provided through Untis were incomplete.
* Importer now automatically fixes intersections of terms with previous terms.
`2.3.2`_ - 2022-09-01
---------------------
......
import logging
from datetime import date
from datetime import date, timedelta
from typing import Dict, Optional
from django.db.models import Max, OuterRef, Q, QuerySet, Subquery
......@@ -71,7 +71,7 @@ def import_terms(
if school_id is None:
school_id = get_site_preferences()["untis_mysql__school_id"]
qs = qs.filter(school_id=school_id)
qs = qs.filter(school_id=school_id).order_by("datefrom")
if version is None:
# Select newest version per term / validity range
......@@ -142,6 +142,7 @@ def import_terms(
school_term.date_start = date_start
school_term.save()
school_terms[school_year_id] = school_term
try:
validity_range = chronos_models.ValidityRange.objects.get(
......@@ -151,13 +152,24 @@ def import_terms(
except chronos_models.ValidityRange.DoesNotExist:
try:
validity_range = chronos_models.ValidityRange.objects.within_dates(
date_start, date_end
date_start__gte=date_start, date_end__lte=date_end
).get()
logger.info(" Validity range found by time.")
except chronos_models.ValidityRange.DoesNotExist:
validity_range = chronos_models.ValidityRange()
logger.info(" Validity range created newly.")
# In Untis, you can set all the end dates of the terms to the same date
# and despite that, the terms still end if a new one starts.
# If this case occurs, we have to set the end date of the previous term
# to the start date of the next one.
validity_range_with_possible_intersection = chronos_models.ValidityRange.objects.filter(
date_end__gte=date_start, date_start__lt=date_start
).first()
if validity_range_with_possible_intersection:
validity_range_with_possible_intersection.date_end = date_start - timedelta(days=1)
validity_range_with_possible_intersection.save()
validity_range.import_ref_untis = term_id
validity_range.date_start = date_start
validity_range.date_end = date_end
......
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