diff options
author | Alban Gruin | 2017-10-19 22:14:28 +0200 |
---|---|---|
committer | Alban Gruin | 2017-10-22 13:16:02 +0200 |
commit | 5489101669d57c834c65f5a889a6d40ce3bcfb1c (patch) | |
tree | f472d5c181ae94a5cb245c4e55b432a7c3bf3dd6 | |
parent | f033f310ac8331de24a5fc2028ba22978c1d941e (diff) |
Changement de la logique de récupération des cours pour un groupe
adaptée à la nouvelle structure du modèle Group.
-rw-r--r-- | models.py | 16 |
1 files changed, 7 insertions, 9 deletions
@@ -13,6 +13,8 @@ # You should have received a copy of the GNU Affero General Public License # along with celcatsanitizer. If not, see <http://www.gnu.org/licenses/>. +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") |