Skip to content
Snippets Groups Projects
Commit 3eaec0a7 authored by Nik | Klampfradler's avatar Nik | Klampfradler
Browse files

Merge branch 'fix/delete-old-lessons' into 'master'

Delete no-longer existing lessons

See merge request AlekSIS/official/AlekSIS-App-Untis!23
parents 89aa0c87 f14e7d94
No related branches found
No related tags found
No related merge requests found
import logging import logging
from datetime import timedelta from datetime import timedelta
import reversion
from django.utils.translation import gettext as _ from django.utils.translation import gettext as _
from tqdm import tqdm from tqdm import tqdm
...@@ -42,9 +43,13 @@ def import_lessons(time_periods_ref, rooms_ref, subjects_ref, teachers_ref, clas ...@@ -42,9 +43,13 @@ def import_lessons(time_periods_ref, rooms_ref, subjects_ref, teachers_ref, clas
# Lessons # Lessons
lessons = run_default_filter(mysql_models.Lesson.objects) lessons = run_default_filter(mysql_models.Lesson.objects)
existing_lessons = []
for lesson in tqdm(lessons, desc="Import lessons", **TQDM_DEFAULTS): for lesson in tqdm(lessons, desc="Import lessons", **TQDM_DEFAULTS):
lesson_id = lesson.lesson_id lesson_id = lesson.lesson_id
existing_lessons.append(lesson_id)
logger.info(_("Import lesson {}").format(lesson_id)) logger.info(_("Import lesson {}").format(lesson_id))
if not lesson.lesson_tt: if not lesson.lesson_tt:
...@@ -263,3 +268,10 @@ def import_lessons(time_periods_ref, rooms_ref, subjects_ref, teachers_ref, clas ...@@ -263,3 +268,10 @@ def import_lessons(time_periods_ref, rooms_ref, subjects_ref, teachers_ref, clas
lesson=lesson, period=time_period, room=room, element_id_untis=j lesson=lesson, period=time_period, room=room, element_id_untis=j
) )
logger.info(" New time period added") logger.info(" New time period added")
for lesson in chronos_models.Lesson.objects.filter(term_untis=term.term_id):
if lesson.lesson_id_untis and lesson.lesson_id_untis not in existing_lessons:
logger.info("Lesson {} deleted".format(lesson.id))
with reversion.create_revision():
lesson.save()
lesson.delete()
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