mirror of
https://gitlab.com/animath/si/plateforme.git
synced 2024-12-24 19:02:23 +00:00
Pool endpoint
This commit is contained in:
parent
14cde3ac91
commit
ac9591c320
@ -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'
|
||||
|
||||
|
@ -2,7 +2,7 @@ from django.urls import path
|
||||
|
||||
from .views import TournamentListView, TournamentCreateView, TournamentDetailView, TournamentUpdateView, \
|
||||
TeamDetailView, TeamUpdateView, AddOrganizerView, SolutionsView, SolutionsOrgaListView, SynthesesView, \
|
||||
SynthesesOrgaListView, PoolListView, PoolCreateView, PoolDetailView
|
||||
SynthesesOrgaListView, PoolListView, PoolCreateView, PoolDetailView, PoolEndpoint
|
||||
|
||||
app_name = "tournament"
|
||||
|
||||
@ -19,6 +19,7 @@ urlpatterns = [
|
||||
path("syntheses/", SynthesesView.as_view(), name="syntheses"),
|
||||
path("all_syntheses/", SynthesesOrgaListView.as_view(), name="all_syntheses"),
|
||||
path("pools/", PoolListView.as_view(), name="pools"),
|
||||
path("pools/add/", PoolCreateView.as_view(), name="create_pool"),
|
||||
path("pool/add/", PoolCreateView.as_view(), name="create_pool"),
|
||||
path("pool/add/endpoint/", PoolEndpoint.as_view(), name="create_pool_endpoint"),
|
||||
path("pool/<int:pk>/", PoolDetailView.as_view(), name="pool_detail"),
|
||||
]
|
||||
|
@ -11,7 +11,10 @@ from django.http import HttpResponse
|
||||
from django.shortcuts import redirect
|
||||
from django.template.loader import render_to_string
|
||||
from django.urls import reverse_lazy
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.views import View
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
from django.views.generic import DetailView, CreateView, UpdateView
|
||||
from django.views.generic.edit import BaseFormView
|
||||
from django_tables2.views import SingleTableView
|
||||
@ -480,4 +483,12 @@ class PoolDetailView(LoginRequiredMixin, DetailView):
|
||||
.format(_("Syntheses of a pool.zip").replace(" ", "%20"))
|
||||
return resp
|
||||
|
||||
return self.get(request, *args, **kwargs)
|
||||
return self.get(request, *args, **kwargs)
|
||||
|
||||
|
||||
@method_decorator(csrf_exempt, 'dispatch')
|
||||
class PoolEndpoint(View):
|
||||
def post(self, request, *args, **kwargs):
|
||||
print(request.headers)
|
||||
print(request.user)
|
||||
print(self.request.POST)
|
||||
|
Loading…
Reference in New Issue
Block a user