aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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")