1
0
mirror of https://gitlab.com/animath/si/plateforme.git synced 2025-06-21 03:58:26 +02:00

Pool endpoint

This commit is contained in:
Yohann D'ANELLO
2020-05-05 05:57:57 +02:00
parent 14cde3ac91
commit ac9591c320
3 changed files with 44 additions and 5 deletions

View File

@ -2,10 +2,10 @@
# SPDX-License-Identifier: GPL-3.0-or-later
from django.conf.urls import url, include
from django.contrib.auth.models import User
from django_filters.rest_framework import DjangoFilterBackend
from rest_framework import routers, serializers
from rest_framework import routers, serializers, status
from rest_framework.filters import SearchFilter
from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet
from member.models import TFJMUser, Authorization, Solution, Synthesis, MotivationLetter
@ -125,6 +125,32 @@ class PoolViewSet(ModelViewSet):
filter_backends = [DjangoFilterBackend]
filterset_fields = ['teams', 'teams__trigram', 'round', ]
def create(self, request, *args, **kwargs):
data = request.data
try:
spl = data.split(";")
if len(spl) >= 7:
round = int(spl[0])
teams = []
solutions = []
for i in range((len(spl) - 1) // 2):
trigram = spl[1 + 2 * i]
pb = int(spl[2 + 2 * i])
team = Team.objects.get(trigram=trigram)
solution = Solution.objects.get(team=team, problem=pb, final=team.selected_for_final)
teams.append(team)
solutions.append(solution)
pool = Pool.objects.create(round=round)
pool.teams.set(teams)
pool.solutions.set(solutions)
pool.save()
serializer = PoolSerializer(pool)
headers = self.get_success_headers(serializer.data)
return Response(serializer.data, status=status.HTTP_201_CREATED, headers=headers)
except BaseException: # JSON data
pass
return super().create(request, *args, **kwargs)
# Routers provide an easy way of automatically determining the URL conf.
# Register each app API router and user viewset
@ -136,6 +162,7 @@ router.register('authorization', AuthorizationViewSet)
router.register('motivation_letter', MotivationLetterViewSet)
router.register('solution', SolutionViewSet)
router.register('synthesis', SynthesisViewSet)
router.register('pool', PoolViewSet)
app_name = 'api'