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

Fix import of lessons: Check if there are lessons from other terms ending in this term

parent 848a5acf
No related branches found
No related tags found
1 merge request!13Resolve "Support import from MySQL"
import logging import logging
from datetime import timedelta
from constance import config from constance import config
from django.utils.translation import gettext as _ from django.utils.translation import gettext as _
...@@ -28,6 +29,18 @@ def import_lessons( ...@@ -28,6 +29,18 @@ def import_lessons(
# Get current term # Get current term
term = get_term() term = get_term()
date_start = untis_date_to_date(term.datefrom)
date_end = untis_date_to_date(term.dateto)
# Get all existing lessons for this term
lessons_in_term = chronos_models.Lesson.objects.filter(
term_untis=term.term_id
).values_list("id", flat=True)
# Set the end date of all lessons from other terms ending in this term to the day before this term starts
chronos_models.Lesson.objects.filter(date_end__gte=date_start).exclude(
id__in=lessons_in_term
).update(date_end=date_start - timedelta(days=1))
# Lessons # Lessons
lessons = run_default_filter(mysql_models.Lesson.objects) lessons = run_default_filter(mysql_models.Lesson.objects)
...@@ -178,10 +191,6 @@ def import_lessons( ...@@ -178,10 +191,6 @@ def import_lessons(
else: else:
groups = course_classes groups = course_classes
# Create new lesson
date_start = untis_date_to_date(term.datefrom)
date_end = untis_date_to_date(term.dateto)
# Get old lesson # Get old lesson
old_lesson_qs = chronos_models.Lesson.objects.filter( old_lesson_qs = chronos_models.Lesson.objects.filter(
lesson_id_untis=lesson_id, element_id_untis=i, term_untis=term.term_id lesson_id_untis=lesson_id, element_id_untis=i, term_untis=term.term_id
......
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