diff --git a/website/involvement/models.py b/website/involvement/models.py index 1dee25a8..9b4f268c 100644 --- a/website/involvement/models.py +++ b/website/involvement/models.py @@ -170,47 +170,34 @@ def get_manual_members(self): ]), FieldPanel('group'), ImageChooserPanel('logo'), - FieldRowPanel([ - FieldPanel('leader_en'), - FieldPanel('leader_sv'), - ]), - FieldPanel('email'), FieldPanel('description_en'), FieldPanel('description_sv'), ])] def official_of(user, pk=False): - # TODO : Is this efficient? - applications = Application.objects.filter( - applicant=user, - status='appointed', - position__term_from__lte=date.today(), - position__term_to__gte=date.today(), - position__role__official=True, - position__role__team_id__isnull=False, - ).select_related('position__role__team') - teams = [] - for i in applications: - if pk: - teams.append(i.position.role.team.pk) - else: - teams.append(i.position.role.team) - - return teams + teams = Team.objects.filter( + roles__official=True, + roles__positions__applications__applicant=user, + roles__positions__applications__status='appointed', + roles__positions__term_from__lte=date.today(), + roles__positions__term_to__gte=date.today(), + ) + if pk: + return teams.values_list('pk', flat=True) + else: + return teams def member_of(user, pk=False): - # TODO: Optimize. groups = user.groups.all() - teams = [] - for group in groups: - if hasattr(group, 'team'): - if pk: - teams.append(group.team.pk) - else: - teams.append(group.team) - return teams + teams = Team.objects.filter( + group__in=groups + ) + if pk: + return teams.values_list('pk', flat=True) + else: + return teams class Role(models.Model): diff --git a/website/involvement/wagtail_hooks.py b/website/involvement/wagtail_hooks.py index 93d2040b..55acd404 100644 --- a/website/involvement/wagtail_hooks.py +++ b/website/involvement/wagtail_hooks.py @@ -22,7 +22,7 @@ class TeamAdmin(ModelAdmin): menu_label = _('Teams') menu_icon = 'fa-sitemap' menu_order = 100 - list_display = ('name_en', 'name_sv', 'email') + list_display = ('name_en', 'name_sv', 'group') search_fields = ('name_en', 'name_sv', 'description_en', 'description_sv') permission_helper_class = RulesPermissionHelper inspect_view_enabled = True