aboutsummaryrefslogtreecommitdiff
path: root/management
diff options
context:
space:
mode:
Diffstat (limited to 'management')
-rw-r--r--management/commands/timetables.py30
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)