diff options
author | Alban Gruin | 2017-09-07 20:22:55 +0200 |
---|---|---|
committer | Alban Gruin | 2017-09-07 20:22:55 +0200 |
commit | 1a605b7390fadd1ad65128590aca9d30743a0510 (patch) | |
tree | d0d469d2650e09ba06a2f4b71448a97c2824d2c5 /management/commands/timetables.py | |
parent | bd236d267bfa6857d062733899ca6db5231ddd1d (diff) |
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.
Diffstat (limited to 'management/commands/timetables.py')
-rw-r--r-- | management/commands/timetables.py | 30 |
1 files changed, 19 insertions, 11 deletions
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) |