From 5489101669d57c834c65f5a889a6d40ce3bcfb1c Mon Sep 17 00:00:00 2001 From: Alban Gruin Date: Thu, 19 Oct 2017 22:14:28 +0200 Subject: Changement de la logique de récupération des cours pour un groupe adaptée à la nouvelle structure du modèle Group. --- models.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'models.py') diff --git a/models.py b/models.py index c69bec3..fe285ac 100644 --- a/models.py +++ b/models.py @@ -13,6 +13,8 @@ # You should have received a copy of the GNU Affero General Public License # along with celcatsanitizer. If not, see . +from functools import reduce + from django.db import models from django.db.models import Count, Manager, Q from django.db.models.functions import ExtractWeek, ExtractYear @@ -147,17 +149,13 @@ class Room(models.Model): class CourseManager(Manager): def get_courses_for_group(self, group, **criteria): - groups_criteria = [] - if group.subgroup is not None: - groups_criteria.append(Q(groups__subgroup__isnull=True) | \ - Q(groups__subgroup=group.subgroup)) - if group.td is not None: - groups_criteria.append(Q(groups__td__isnull=True) | Q(groups__td=group.td)) - if group.tp is not None: - groups_criteria.append(Q(groups__tp__isnull=True) | Q(groups__tp=group.tp)) + groups_criteria = reduce(lambda x, y: x | y, + [Q(groups__subgroup=group.subgroup[:i]) + for i in range(1, len(group.subgroup))]) | \ + Q(groups__subgroup__isnull=True) return self.get_queryset() \ - .filter(*groups_criteria, + .filter(groups_criteria, groups__mention=group.mention, timetable=group.timetable, **criteria) \ .order_by("begin") -- cgit v1.2.1