From 7a34fc91521373dddacd1595354da53187d46a5d Mon Sep 17 00:00:00 2001 From: Alban Gruin Date: Sat, 30 Sep 2017 16:30:21 +0200 Subject: 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). --- management/commands/timetables.py | 26 ++++++++++++++++---------- 1 file 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() -- cgit v1.2.1