Skip to content

Commit

Permalink
filter rankings by eligibility (#904)
Browse files Browse the repository at this point in the history
  • Loading branch information
lowtorola authored Jan 13, 2025
1 parent 88c68ed commit ff35628
Show file tree
Hide file tree
Showing 17 changed files with 354 additions and 88 deletions.
9 changes: 9 additions & 0 deletions backend/siarnaq/api/teams/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,12 @@ def filter_queryset(self, request, queryset, view):
if "has_active_submission" not in request.query_params:
return queryset
return queryset.filter(submissions__accepted=True).distinct()


class TeamEligibilityFilter(filters.BaseFilterBackend):
def filter_queryset(self, request, queryset, view):
if "eligible_for" not in request.query_params:
return queryset
return queryset.filter(
profile__eligible_for__in=request.query_params.getlist("eligible_for")
)
24 changes: 22 additions & 2 deletions backend/siarnaq/api/teams/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@
from django.db import transaction
from django.http import Http404
from django.shortcuts import get_object_or_404
from drf_spectacular.utils import extend_schema
from drf_spectacular.utils import OpenApiParameter, extend_schema
from rest_framework import filters, mixins, status, viewsets
from rest_framework.decorators import action
from rest_framework.permissions import IsAdminUser, IsAuthenticated
from rest_framework.response import Response

from siarnaq.api.episodes.permissions import IsEpisodeAvailable
from siarnaq.api.teams.exceptions import TeamMaxSizeExceeded
from siarnaq.api.teams.filters import TeamActiveSubmissionFilter, TeamOrderingFilter
from siarnaq.api.teams.filters import (
TeamActiveSubmissionFilter,
TeamEligibilityFilter,
TeamOrderingFilter,
)
from siarnaq.api.teams.models import ClassRequirement, Team, TeamStatus
from siarnaq.api.teams.permissions import IsOnTeam
from siarnaq.api.teams.serializers import (
Expand All @@ -34,6 +38,21 @@
logger = structlog.get_logger(__name__)


@extend_schema(
parameters=[
OpenApiParameter(
name="has_active_submission",
type=bool,
description="Filter teams by active submission status",
),
OpenApiParameter(
name="eligible_for",
type=int,
many=True,
description="Filter teams by a set of eligibility criteria ID",
),
]
)
class TeamViewSet(
viewsets.GenericViewSet,
mixins.CreateModelMixin,
Expand All @@ -50,6 +69,7 @@ class TeamViewSet(
filters.SearchFilter,
TeamOrderingFilter,
TeamActiveSubmissionFilter,
TeamEligibilityFilter,
]
ordering = "pk"
ordering_fields = ["pk", "name"] + TeamOrderingFilter.ordering_fields
Expand Down
108 changes: 108 additions & 0 deletions frontend/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1283,12 +1283,24 @@ paths:
When creating a team, add the logged in user as the sole member.
parameters:
- in: query
name: eligible_for
schema:
type: array
items:
type: integer
description: Filter teams by a set of eligibility criteria ID
- in: path
name: episode_id
schema:
type: string
pattern: ^[^\/.]+$
required: true
- in: query
name: has_active_submission
schema:
type: boolean
description: Filter teams by active submission status
- name: ordering
required: false
in: query
Expand Down Expand Up @@ -1325,12 +1337,24 @@ paths:
When creating a team, add the logged in user as the sole member.
parameters:
- in: query
name: eligible_for
schema:
type: array
items:
type: integer
description: Filter teams by a set of eligibility criteria ID
- in: path
name: episode_id
schema:
type: string
pattern: ^[^\/.]+$
required: true
- in: query
name: has_active_submission
schema:
type: boolean
description: Filter teams by active submission status
tags:
- team
requestBody:
Expand Down Expand Up @@ -1362,12 +1386,24 @@ paths:
When creating a team, add the logged in user as the sole member.
parameters:
- in: query
name: eligible_for
schema:
type: array
items:
type: integer
description: Filter teams by a set of eligibility criteria ID
- in: path
name: episode_id
schema:
type: string
pattern: ^[^\/.]+$
required: true
- in: query
name: has_active_submission
schema:
type: boolean
description: Filter teams by active submission status
- in: path
name: id
schema:
Expand All @@ -1389,12 +1425,24 @@ paths:
operationId: team_t_avatar_create
description: Update uploaded avatar.
parameters:
- in: query
name: eligible_for
schema:
type: array
items:
type: integer
description: Filter teams by a set of eligibility criteria ID
- in: path
name: episode_id
schema:
type: string
pattern: ^[^\/.]+$
required: true
- in: query
name: has_active_submission
schema:
type: boolean
description: Filter teams by active submission status
tags:
- team
requestBody:
Expand All @@ -1419,12 +1467,24 @@ paths:
When creating a team, add the logged in user as the sole member.
parameters:
- in: query
name: eligible_for
schema:
type: array
items:
type: integer
description: Filter teams by a set of eligibility criteria ID
- in: path
name: episode_id
schema:
type: string
pattern: ^[^\/.]+$
required: true
- in: query
name: has_active_submission
schema:
type: boolean
description: Filter teams by active submission status
tags:
- team
requestBody:
Expand All @@ -1449,12 +1509,24 @@ paths:
operationId: team_t_leave_create
description: Leave a team.
parameters:
- in: query
name: eligible_for
schema:
type: array
items:
type: integer
description: Filter teams by a set of eligibility criteria ID
- in: path
name: episode_id
schema:
type: string
pattern: ^[^\/.]+$
required: true
- in: query
name: has_active_submission
schema:
type: boolean
description: Filter teams by active submission status
tags:
- team
security:
Expand All @@ -1467,12 +1539,24 @@ paths:
operationId: team_t_me_retrieve
description: Retrieve or update information about the current team.
parameters:
- in: query
name: eligible_for
schema:
type: array
items:
type: integer
description: Filter teams by a set of eligibility criteria ID
- in: path
name: episode_id
schema:
type: string
pattern: ^[^\/.]+$
required: true
- in: query
name: has_active_submission
schema:
type: boolean
description: Filter teams by active submission status
tags:
- team
security:
Expand All @@ -1488,12 +1572,24 @@ paths:
operationId: team_t_me_update
description: Retrieve or update information about the current team.
parameters:
- in: query
name: eligible_for
schema:
type: array
items:
type: integer
description: Filter teams by a set of eligibility criteria ID
- in: path
name: episode_id
schema:
type: string
pattern: ^[^\/.]+$
required: true
- in: query
name: has_active_submission
schema:
type: boolean
description: Filter teams by active submission status
tags:
- team
requestBody:
Expand All @@ -1520,12 +1616,24 @@ paths:
operationId: team_t_me_partial_update
description: Retrieve or update information about the current team.
parameters:
- in: query
name: eligible_for
schema:
type: array
items:
type: integer
description: Filter teams by a set of eligibility criteria ID
- in: path
name: episode_id
schema:
type: string
pattern: ^[^\/.]+$
required: true
- in: query
name: has_active_submission
schema:
type: boolean
description: Filter teams by active submission status
tags:
- team
requestBody:
Expand Down
Loading

0 comments on commit ff35628

Please sign in to comment.