From 8861bddccf458846e12e679704a8514ec2dc2510 Mon Sep 17 00:00:00 2001 From: Alban Gruin Date: Fri, 3 Feb 2017 10:43:13 +0100 Subject: Ajout d'un système de renommage de groupe à la volée pour corriger les défauts de nom de la source --- management/commands/_private.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'management') 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 -- cgit v1.2.1