diff options
Diffstat (limited to 'management/commands/timetables.py')
-rw-r--r-- | management/commands/timetables.py | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/management/commands/timetables.py b/management/commands/timetables.py index 76f0a7c..8b37a5d 100644 --- a/management/commands/timetables.py +++ b/management/commands/timetables.py @@ -27,6 +27,7 @@ from ._private import delete_courses_in_week, get_events, get_update_date, get_w @transaction.atomic def process_timetable_week(timetable, soup, weeks_in_soup, force, year=None, week=None): criteria = {} + today = timezone.make_aware(datetime.now()) if year is not None and week is not None: begin, end = get_week(year, week) criteria["begin__gte"] = begin @@ -42,12 +43,12 @@ def process_timetable_week(timetable, soup, weeks_in_soup, force, year=None, wee return if year is not None and week is not None: - delete_courses_in_week(timetable, year, week) + delete_courses_in_week(timetable, year, week, today) else: - Course.objects.filter(timetable=timetable, - begin__gte=min(weeks_in_soup.values())).delete() + delete_from = max(min(weeks_in_soup.values()), today) + Course.objects.filter(timetable=timetable, begin__gte=delete_from).delete() - for course in get_events(timetable, soup, weeks_in_soup, year, week): + for course in get_events(timetable, soup, weeks_in_soup, today, year, week): course.save() timetable.last_update_date = new_update_date |