diff options
author | Alban Gruin | 2017-09-24 17:16:10 +0200 |
---|---|---|
committer | Alban Gruin | 2017-09-24 17:16:10 +0200 |
commit | e30b0c673cae607175c5bae6df6e87d8b100bdf3 (patch) | |
tree | 2ffc269ad5e56ff93e2ecd3bded5843a585c4fe7 /management/commands | |
parent | 77748ec01d1ef59d8436597a9b52675b309e1c4d (diff) |
Suppression du modèle LastUpdate, utilisation du champ last_update à
la place.
Diffstat (limited to 'management/commands')
-rw-r--r-- | management/commands/cleancourses.py | 4 | ||||
-rw-r--r-- | management/commands/timetables.py | 18 |
2 files changed, 8 insertions, 14 deletions
diff --git a/management/commands/cleancourses.py b/management/commands/cleancourses.py index ca2ef94..f6041ef 100644 --- a/management/commands/cleancourses.py +++ b/management/commands/cleancourses.py @@ -15,7 +15,7 @@ from django.core.management.base import BaseCommand from django.db import transaction -from edt.models import Course, Group, LastUpdate +from edt.models import Course, Group class Command(BaseCommand): @@ -29,10 +29,8 @@ class Command(BaseCommand): if options["timetable"] is None: Course.objects.all().delete() Group.objects.all().delete() - LastUpdate.objects.all().delete() else: Course.objects.filter(timetable__id__in=options["timetable"]).delete() Group.objects.filter(timetable__id__in=options["timetable"]).delete() - LastUpdate.objects.filter(timetable__id__in=options["timetable"]).delete() self.stdout.write(self.style.SUCCESS("Done.")) diff --git a/management/commands/timetables.py b/management/commands/timetables.py index c82b0e4..45a57ee 100644 --- a/management/commands/timetables.py +++ b/management/commands/timetables.py @@ -17,20 +17,19 @@ 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 edt.models import Timetable, Course +from edt.utils import get_week 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 + begin, end = get_weeks(year, week) + + last_update_date = Course.objects.filter(begin__gte=start, begin__lt=end).aggregate(Max("last_update"))["last_update__max"] 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(timetable=timetable, year=year, week=week) + updated_at = timezone.make_aware(datetime.datetime.now()) if last_update_date is not None and new_update_date is not None and \ last_update_date >= new_update_date: @@ -43,6 +42,7 @@ def process_timetable_week(timetable, year, week, soup, weeks_in_soup): course.name = name course.type = type_ course.notes = notes + course.updated_at = updated_at course.groups.add(*groups) if rooms is not None: @@ -50,10 +50,6 @@ def process_timetable_week(timetable, year, week, soup, weeks_in_soup): course.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) weeks_in_soup = get_weeks(soup) |