diff options
Diffstat (limited to 'management/commands/timetables.py')
-rw-r--r-- | management/commands/timetables.py | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/management/commands/timetables.py b/management/commands/timetables.py index c5c6dfa..58c86fd 100644 --- a/management/commands/timetables.py +++ b/management/commands/timetables.py @@ -17,29 +17,35 @@ import datetime from django.core.management.base import BaseCommand from django.db import transaction -from django.db.models import Max +from django.db.models import Min from django.utils import timezone -from edt.models import Timetable, Course +from edt.models import Course, Timetable from edt.utils import get_week from ._private import delete_courses_in_week, get_events, get_update_date, get_weeks, get_xml @transaction.atomic def process_timetable_week(timetable, soup, weeks_in_soup, force, year=None, week=None): - begin, end = get_week(year, week) - - last_update_date = Course.objects.filter(timetable=timetable, - begin__gte=begin, - begin__lt=end) \ - .aggregate(Max("last_update")) \ - ["last_update__max"] + criteria = {} + if year is not None and week is not None: + begin, end = get_week(year, week) + criteria["begin__gte"] = begin + criteria["begin__lt"] = end + + last_update_date = Course.objects.filter(timetable=timetable, **criteria) \ + .aggregate(Min("last_update")) \ + ["last_update__min"] new_update_date = get_update_date(soup) if not force and last_update_date is not None and new_update_date is not None and \ last_update_date >= new_update_date: return - delete_courses_in_week(timetable, year, week) + if year is not None and week is not None: + delete_courses_in_week(timetable, year, week) + else: + Course.objects.filter(timetable=timetable).delete() + for course in get_events(timetable, soup, weeks_in_soup, year, week): course.save() |