2022-05-03 02:44:14 +00:00
|
|
|
from django.http import HttpResponseBadRequest, JsonResponse
|
|
|
|
from django.db import transaction
|
|
|
|
|
|
|
|
from judge.models import VolunteerProblemVote, Problem, ProblemType
|
|
|
|
|
|
|
|
|
|
|
|
def vote_problem(request):
|
2022-05-14 17:57:27 +00:00
|
|
|
if not request.user or not request.user.has_perm("judge.suggest_problem_changes"):
|
2022-05-03 02:44:14 +00:00
|
|
|
return HttpResponseBadRequest()
|
2022-05-14 17:57:27 +00:00
|
|
|
if not request.method == "POST":
|
2022-05-03 02:44:14 +00:00
|
|
|
return HttpResponseBadRequest()
|
|
|
|
try:
|
2022-05-14 17:57:27 +00:00
|
|
|
types_id = request.POST.getlist("types[]")
|
2022-05-03 02:44:14 +00:00
|
|
|
types = ProblemType.objects.filter(id__in=types_id)
|
2022-05-14 17:57:27 +00:00
|
|
|
problem = Problem.objects.get(code=request.POST["problem"])
|
|
|
|
knowledge_points = request.POST["knowledge_points"]
|
|
|
|
thinking_points = request.POST["thinking_points"]
|
|
|
|
feedback = request.POST["feedback"]
|
2022-05-03 02:44:14 +00:00
|
|
|
except Exception as e:
|
|
|
|
return HttpResponseBadRequest()
|
|
|
|
|
2024-02-19 23:00:44 +00:00
|
|
|
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()
|
2022-05-03 02:44:14 +00:00
|
|
|
return JsonResponse({})
|