Add problem volunteer
This commit is contained in:
parent
e51129d36f
commit
e70618ed19
15 changed files with 396 additions and 5 deletions
33
judge/views/volunteer.py
Normal file
33
judge/views/volunteer.py
Normal file
|
@ -0,0 +1,33 @@
|
|||
from django.http import HttpResponseBadRequest, JsonResponse
|
||||
from django.db import transaction
|
||||
|
||||
from judge.models import VolunteerProblemVote, Problem, ProblemType
|
||||
|
||||
|
||||
def vote_problem(request):
|
||||
if not request.user or not request.user.has_perm('judge.suggest_problem_changes'):
|
||||
return HttpResponseBadRequest()
|
||||
if not request.method == 'POST':
|
||||
return HttpResponseBadRequest()
|
||||
try:
|
||||
types_id = request.POST.getlist('types[]')
|
||||
types = ProblemType.objects.filter(id__in=types_id)
|
||||
problem = Problem.objects.get(code=request.POST['problem'])
|
||||
knowledge_points = request.POST['knowledge_points']
|
||||
thinking_points = request.POST['thinking_points']
|
||||
feedback = request.POST['feedback']
|
||||
except Exception as e:
|
||||
return HttpResponseBadRequest()
|
||||
|
||||
with transaction.atomic():
|
||||
vote, _ = VolunteerProblemVote.objects.get_or_create(
|
||||
voter=request.profile,
|
||||
problem=problem,
|
||||
defaults={'knowledge_points': 0, 'thinking_points': 0},
|
||||
)
|
||||
vote.knowledge_points = knowledge_points
|
||||
vote.thinking_points = thinking_points
|
||||
vote.feedback = feedback
|
||||
vote.types.set(types)
|
||||
vote.save()
|
||||
return JsonResponse({})
|
Loading…
Add table
Add a link
Reference in a new issue