aboutsummaryrefslogtreecommitdiff
path: root/management/commands
diff options
context:
space:
mode:
authorAlban Gruin2017-09-10 11:54:38 +0200
committerAlban Gruin2017-09-12 21:40:28 +0200
commit32bd236f2c53bc8dfd515018a7ae0ec06f65c115 (patch)
tree9e577d0ad4131ae92135d497b9f5ea6677302f7b /management/commands
parent445bfdcde5309645ac4d6f5c1d565530e6dbfeed (diff)
La consolidation a lieu pour le parent d’un groupe mais aussi ses enfants
Diffstat (limited to 'management/commands')
-rw-r--r--management/commands/_private.py31
1 files changed, 23 insertions, 8 deletions
diff --git a/management/commands/_private.py b/management/commands/_private.py
index 2b57599..c140f51 100644
--- a/management/commands/_private.py
+++ b/management/commands/_private.py
@@ -45,19 +45,34 @@ def add_time(date, time):
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.subgroup is not None:
+ group_content = dict(zip(group_content_key, group_content_list))
- if group_content_list[i] is not None:
- break
+ 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 "subgroup" in group_content:
- group.parent = Group.objects.filter(**group_content).first()
+ if group_content_list[i] is not None:
+ break
+
+ group.parent = Group.objects.filter(timetable=group.timetable,
+ **group_content).first()
group.save()
+ if group.tp is None:
+ group_content = dict(zip(group_content_key, group_content_list))
+ last_is_none = False
+
+ for i, key in enumerate(group_content_key):
+ if group_content_list[i] is None or last_is_none:
+ del group_content[key]
+ group_content[key + "__isnull"] = last_is_none
+ last_is_none = True
+
+ Group.objects.filter(timetable=group.timetable, parent__isnull=True,
+ **group_content).update(parent=group)
+
def consolidate_groups(groups):
for group in groups:
if group.parent == None: