aboutsummaryrefslogtreecommitdiff
path: root/management/commands/timetables.py
diff options
context:
space:
mode:
Diffstat (limited to 'management/commands/timetables.py')
-rw-r--r--management/commands/timetables.py25
1 files changed, 8 insertions, 17 deletions
diff --git a/management/commands/timetables.py b/management/commands/timetables.py
index f01ac3c..7ee63af 100644
--- a/management/commands/timetables.py
+++ b/management/commands/timetables.py
@@ -25,7 +25,7 @@ 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, year, week, soup, weeks_in_soup):
+def process_timetable_week(timetable, soup, weeks_in_soup, year=None, week=None):
begin, end = get_week(year, week)
last_update_date = Course.objects.filter(timetable=timetable,
@@ -40,27 +40,18 @@ def process_timetable_week(timetable, year, week, soup, weeks_in_soup):
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):
- course = Course.objects.create(timetable=timetable,
- begin=begin,
- end=end)
- course.name = name
- course.type = type_
- course.notes = notes
-
- course.groups.add(*groups)
- if rooms is not None:
- course.rooms.add(*rooms)
-
+ for course in get_events(timetable, soup, weeks_in_soup, year, week):
course.save()
-def process_timetable(timetable, year, weeks):
+def process_timetable(timetable, year=None, weeks=None):
soup = get_xml(timetable.url)
weeks_in_soup = get_weeks(soup)
- for week in weeks:
- process_timetable_week(timetable, year, week, soup, weeks_in_soup)
+ if year is not None and weeks is not None:
+ for week in weeks:
+ process_timetable_week(timetable, soup, weeks_in_soup, year, week)
+ else:
+ process_timetable_week(timetable, soup, weeks_in_soup)
class Command(BaseCommand):