This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from rest_framework import viewsets, permissions, status, filters, serializers
|
||||
from rest_framework.decorators import action
|
||||
from rest_framework.decorators import action, api_view, permission_classes
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.views import APIView
|
||||
from django.db.models import Q
|
||||
from shop.utils import get_current_wechat_user
|
||||
from .models import Competition, CompetitionEnrollment, Project, ProjectFile, Score, Comment, ScoreDimension
|
||||
@@ -280,3 +281,31 @@ class CommentViewSet(viewsets.ModelViewSet):
|
||||
raise serializers.ValidationError("您不是该比赛的评委")
|
||||
|
||||
serializer.save(judge=enrollment)
|
||||
|
||||
|
||||
class CompetitionDimensionsAPIView(APIView):
|
||||
"""
|
||||
获取比赛评分维度的API
|
||||
"""
|
||||
permission_classes = [permissions.AllowAny]
|
||||
|
||||
def get(self, request, competition_id):
|
||||
try:
|
||||
competition = Competition.objects.get(id=competition_id)
|
||||
dimensions = ScoreDimension.objects.filter(competition=competition).order_by('order')
|
||||
|
||||
data = {
|
||||
'dimensions': [
|
||||
{
|
||||
'id': d.id,
|
||||
'name': d.name,
|
||||
'weight': float(d.weight),
|
||||
'max_score': d.max_score,
|
||||
'description': d.description
|
||||
}
|
||||
for d in dimensions
|
||||
]
|
||||
}
|
||||
return Response(data)
|
||||
except Competition.DoesNotExist:
|
||||
return Response({'error': '比赛不存在'}, status=404)
|
||||
|
||||
Reference in New Issue
Block a user