diff --git a/biscuit/apps/untis/util.py b/biscuit/apps/untis/util.py index de2e03034c97a9b76f345be5823568d2a735b29d..45ef67c7248bd5fa74fd2cb9d50c4d9f8d810af4 100644 --- a/biscuit/apps/untis/util.py +++ b/biscuit/apps/untis/util.py @@ -1,4 +1,4 @@ -from datetime import date, time +from datetime import date, time, timedelta from typing import BinaryIO, Optional, Union from xml.dom import minidom, Node @@ -81,7 +81,13 @@ def untis_import_xml(request: HttpRequest, untis_xml: Union[BinaryIO, str]) -> N messages.warning(request, _('Could not set class teacher of %(class)s to %(teacher)s.') % { 'class': short_name, 'teacher': class_teacher_short_name}) - Lesson.objects.all().delete() + # Set all existing lessons that overlap to end today + today = date.today() + Lesson.objects.filter( + date_end__gt=today + ).update( + date_end=today + ) lessons = dom.getElementsByTagName('lesson') for lesson_node in lessons: @@ -113,6 +119,10 @@ def untis_import_xml(request: HttpRequest, untis_xml: Union[BinaryIO, str]) -> N date_end = date(int(effectiveenddate[:4]), int(effectiveenddate[4:6]), int( effectiveenddate[6:])) if effectiveenddate else None + # Coerce effective start date to not be before tomorrow + if date_start and date_start <= today: + date_start = today + timedelta(days=1) + try: groups = [Group.objects.get(short_name=v) for v in group_short_names]