From 1a605b7390fadd1ad65128590aca9d30743a0510 Mon Sep 17 00:00:00 2001 From: Alban Gruin Date: Thu, 7 Sep 2017 20:22:55 +0200 Subject: On ne parse pas le contenu de l’emploi du temps si la date de mise à jour est égale ou inférieure à celle stockée en base de données. --- management/commands/timetables.py | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) (limited to 'management/commands/timetables.py') diff --git a/management/commands/timetables.py b/management/commands/timetables.py index d596233..7f33be1 100644 --- a/management/commands/timetables.py +++ b/management/commands/timetables.py @@ -17,16 +17,29 @@ from django.core.management.base import BaseCommand from django.db import transaction from django.utils import timezone -from edt.models import Timetable, LastUpdate, Course -from ._private import delete_courses_in_week, get_events, get_weeks, get_xml +from edt.models import Timetable, LastUpdate, Course +from ._private import delete_courses_in_week, get_events, get_update_date, get_weeks, get_xml import datetime @transaction.atomic def process_timetable_week(timetable, year, week, soup, weeks_in_soup): + last_update_date = None + new_update_date = get_update_date(soup) + try: + last_update = LastUpdate.objects.get(timetable=timetable, year=year, week=week) + last_update_date = last_update.updated_at + except: + last_update = LastUpdate.objects(timetable=timetable, year=year, week=week) + + if 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) - for name, type_, groups, rooms, notes, begin, end in get_events(timetable, year, week, soup, weeks_in_soup): + for name, type_, groups, rooms, notes, begin, end in \ + get_events(timetable, year, week, soup, weeks_in_soup): course = Course.objects.create(timetable=timetable, begin=begin, end=end) course.name = name course.type = type_ @@ -38,14 +51,9 @@ def process_timetable_week(timetable, year, week, soup, weeks_in_soup): course.save() - date = timezone.make_aware(datetime.datetime.now()) - try: - last_update = LastUpdate.objects.get(timetable=timetable, year=year, week=week) - last_update.date = date - except: - last_update = LastUpdate(timetable=timetable, year=year, week=week, date=date) - finally: - last_update.save() + last_update.date = timezone.make_aware(datetime.datetime.now()) + last_update.updated_at = new_update_date + last_update.save() def process_timetable(timetable, year, weeks): soup = get_xml(timetable.url) -- cgit v1.2.1 From 702ed90e13396bd999079d22f03a40e4daf93a54 Mon Sep 17 00:00:00 2001 From: Alban Gruin Date: Thu, 7 Sep 2017 20:28:48 +0200 Subject: Correction de la création de l’objet LastUpdate --- management/commands/timetables.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'management/commands/timetables.py') diff --git a/management/commands/timetables.py b/management/commands/timetables.py index 7f33be1..64dd6f6 100644 --- a/management/commands/timetables.py +++ b/management/commands/timetables.py @@ -31,7 +31,7 @@ def process_timetable_week(timetable, year, week, soup, weeks_in_soup): last_update = LastUpdate.objects.get(timetable=timetable, year=year, week=week) last_update_date = last_update.updated_at except: - last_update = LastUpdate.objects(timetable=timetable, year=year, week=week) + last_update = LastUpdate(timetable=timetable, year=year, week=week) if last_update_date is not None and new_update_date is not None and \ last_update_date >= new_update_date: -- cgit v1.2.1 From 49e56d97e5a126f66d1d52b5de45befe603893b2 Mon Sep 17 00:00:00 2001 From: Alban Gruin Date: Thu, 7 Sep 2017 23:31:54 +0200 Subject: Remplacement de la licence GPL 2 par la licence AGPL 3 --- management/commands/timetables.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'management/commands/timetables.py') diff --git a/management/commands/timetables.py b/management/commands/timetables.py index 64dd6f6..c82b0e4 100644 --- a/management/commands/timetables.py +++ b/management/commands/timetables.py @@ -1,18 +1,17 @@ # Copyright (C) 2017 Alban Gruin # -# celcatsanitizer is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or +# celcatsanitizer is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # celcatsanitizer is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# GNU Affero General Public License for more details. # -# You should have received a copy of the GNU General Public License along -# with celcatsanitizer; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# You should have received a copy of the GNU Affero General Public License +# along with celcatsanitizer. If not, see . from django.core.management.base import BaseCommand from django.db import transaction -- cgit v1.2.1