diff options
author | Alban Gruin | 2017-09-30 16:30:21 +0200 |
---|---|---|
committer | Alban Gruin | 2017-09-30 16:30:21 +0200 |
commit | 7a34fc91521373dddacd1595354da53187d46a5d (patch) | |
tree | 9503a11cf96ee58f950e907be2ac1088ee965a70 /management/commands/timetables.py | |
parent | 45402cbdab2dfdbd9e2f72c70d27f966f932789b (diff) |
Suppression de tous les cours d’un edt si jamais aucune semaine n’est
fournie.
Pas de filtre de début ou de fin dans le cas où aucune semaine n’est
fournie.
Changement du type d’aggrégation (minimum au lieu de maximum).
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() |