diff options
author | Alban Gruin | 2017-02-03 10:43:13 +0100 |
---|---|---|
committer | Alban Gruin | 2017-02-03 10:43:13 +0100 |
commit | 8861bddccf458846e12e679704a8514ec2dc2510 (patch) | |
tree | feaf18628e54a71a475fc73f363adf107ffe07f6 /management | |
parent | bfa5715f6deaa71ad51811bd2f59cdd330b860d9 (diff) |
Ajout d'un système de renommage de groupe à la volée pour corriger les défauts de nom de la sourcev0.3.0
Diffstat (limited to 'management')
-rw-r--r-- | management/commands/_private.py | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/management/commands/_private.py b/management/commands/_private.py index f5a3ebc..3ff9316 100644 --- a/management/commands/_private.py +++ b/management/commands/_private.py @@ -29,14 +29,14 @@ def delete_courses_in_week(timetable, year, week): Course.objects.filter(begin__gte=start, begin__lt=end, timetable=timetable).delete() -def get_from_db_or_create(cls, name, timetable=None): - obj = cls.objects.all().filter(name=name) +def get_from_db_or_create(cls, timetable=None, **kwargs): + obj = cls.objects.all().filter(**kwargs) if timetable is not None: obj = obj.filter(timetable=timetable) obj = obj.first() if obj is None: - obj = cls(name=name) + obj = cls(**kwargs) obj.timetable = timetable obj.save() @@ -61,7 +61,8 @@ def get_events(soup, weeks, year, week, timetable): end = add_time(date, datetime.datetime.strptime( event.endtime.text, "%H:%M")) - groups = [get_from_db_or_create(Group, item.text, timetable) + groups = [get_from_db_or_create(Group, timetable, + celcat_name=item.text) for item in event.resources.group.find_all("item")] if event.notes is not None: @@ -79,7 +80,7 @@ def get_events(soup, weeks, year, week, timetable): type_ = event.category.text if event.resources.room is not None: - rooms = [get_from_db_or_create(Room, item.text) + rooms = [get_from_db_or_create(Room, name=item.text) for item in event.resources.room.find_all("item")] yield title, type_, groups, rooms, notes, begin, end |