aboutsummaryrefslogtreecommitdiff
path: root/management/commands/_private.py
diff options
context:
space:
mode:
authorAlban Gruin2017-09-04 21:42:25 +0200
committerAlban Gruin2017-09-04 21:42:25 +0200
commit276158c7813cb75df3ea433d3b8543bdf5c7b7d3 (patch)
tree455bc1ecfb6f005656e65e2fadbaaf6ff2a81334 /management/commands/_private.py
parent6302ee0f04702c21101f07377b5f2484a165cf16 (diff)
On trouve le parent de chaque groupe à sa création par le parseur
d’emploi du temps, et pas autre part. Si jamais le parent est déjà connu, on ignore cette étape.
Diffstat (limited to 'management/commands/_private.py')
-rw-r--r--management/commands/_private.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/management/commands/_private.py b/management/commands/_private.py
index 3cd23ca..dec13cd 100644
--- a/management/commands/_private.py
+++ b/management/commands/_private.py
@@ -41,6 +41,27 @@ def add_time(date, time):
delta = datetime.timedelta(hours=time.hour, minutes=time.minute)
return date + delta
+def consolidate_group(group):
+ group_content_key = ("mention", "subgroup", "td", "tp")
+ group_content_list = group.group_info[1:]
+ group_content = dict(zip(group_content_key, group_content_list))
+
+ for i in range(len(group_content_list))[::-1]:
+ del group_content[group_content_key[i]]
+ group_content[group_content_key[i] + "__isnull"] = True
+
+ if group_content_list[i] is not None:
+ break
+
+ if "subgroup" in group_content:
+ group.parent_group = Group.objects.filter(**group_content).first()
+ group.save()
+
+def consolidate_groups(groups):
+ for group in groups:
+ if group.parent_group == None:
+ consolidate_group(group)
+
def delete_courses_in_week(timetable, year, week):
start, end = get_week(year, week)
Course.objects.filter(begin__gte=start, begin__lt=end,
@@ -79,6 +100,7 @@ def get_events(timetable, year, week, soup, weeks_in_soup):
groups = [get_from_db_or_create(Group, timetable=timetable,
celcat_name=item.text)
for item in event.resources.group.find_all("item")]
+ consolidate_groups(groups)
if event.notes is not None:
notes = event.notes.text