diff options
author | Alban Gruin | 2017-09-29 21:19:01 +0200 |
---|---|---|
committer | Alban Gruin | 2017-09-29 21:19:01 +0200 |
commit | a8d35aee63f073674993b8afde78a8d5c1517e05 (patch) | |
tree | 610cad6bd9718bca17cd68b2e5913cb7b289ec8f /management/commands/timetables.py | |
parent | a30de7e84c7c7208f76178586befe5374cd1e02d (diff) |
get_events() renvoie des objets Course au lieu d’un tuple de données.
Ajout de commentaires dans la fonction get_events()
Les paramètres year et week des fonctions get_events(),
process_timetable_week() et process_timetable() sont maintenant
optionnels.
Diffstat (limited to 'management/commands/timetables.py')
-rw-r--r-- | management/commands/timetables.py | 25 |
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): |