|
| 1 | +# Copyright The IETF Trust 2012-2019, All Rights Reserved |
| 2 | +# -*- coding: utf-8 -*- |
| 3 | + |
1 | 4 | import os |
2 | 5 |
|
| 6 | +from django.db.models import Q |
3 | 7 | from django.shortcuts import get_object_or_404 |
4 | 8 | from django.utils.safestring import mark_safe |
5 | 9 | from django.urls import reverse as urlreverse |
|
11 | 15 | from ietf.doc.models import Document, State |
12 | 16 | from ietf.group.models import Group, RoleHistory, Role |
13 | 17 | from ietf.ietfauth.utils import has_role |
| 18 | +from ietf.name.models import GroupTypeName |
14 | 19 | from ietf.person.models import Email |
15 | 20 | from ietf.review.utils import can_manage_review_requests_for_team |
16 | 21 | from ietf.utils import log |
@@ -246,3 +251,23 @@ def construct_group_menu_context(request, group, selected, group_type, others): |
246 | 251 | d.update(others) |
247 | 252 |
|
248 | 253 | return d |
| 254 | + |
| 255 | + |
| 256 | +def group_features_group_filter(groups, person, feature): |
| 257 | + """This returns a queryset of groups filtered such that the given person has |
| 258 | + a role listed in the given feature for each group.""" |
| 259 | + type_slugs = set(groups.values_list('type__slug', flat=True)) |
| 260 | + group_types = GroupTypeName.objects.filter(slug__in=type_slugs) |
| 261 | + if not group_types.exists(): |
| 262 | + return groups.none() |
| 263 | + q = reduce(lambda a,b:a|b, [ Q(role__person=person, role__name__slug__in=getattr(t.features, feature)) for t in group_types ]) |
| 264 | + return groups.filter(q) |
| 265 | + |
| 266 | +def group_features_role_filter(roles, person, feature): |
| 267 | + type_slugs = set(roles.values_list('group__type__slug', flat=True)) |
| 268 | + group_types = GroupTypeName.objects.filter(slug__in=type_slugs) |
| 269 | + if not group_types.exists(): |
| 270 | + return roles.none() |
| 271 | + q = reduce(lambda a,b:a|b, [ Q(person=person, name__slug__in=getattr(t.features, feature)) for t in group_types ]) |
| 272 | + return roles.filter(q) |
| 273 | + |
0 commit comments