aboutsummaryrefslogtreecommitdiff
path: root/models.py
diff options
context:
space:
mode:
authorAlban Gruin2017-10-19 22:14:28 +0200
committerAlban Gruin2017-10-19 22:14:28 +0200
commitacc4475efca6326f59673d88865eecbef0511755 (patch)
tree9f9d1f5e23c6dc88ef1ee6ccb009b06d7960b304 /models.py
parent9efb1796aed00f4c7a8c9cd7e6b8a169318b1be0 (diff)
Changement de la logique de récupération des cours pour un groupe
adaptée à la nouvelle structure du modèle Group.
Diffstat (limited to 'models.py')
-rw-r--r--models.py16
1 files changed, 7 insertions, 9 deletions
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 <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")