.
This commit is contained in:
+24
-5
@@ -20,6 +20,7 @@ from django.urls import reverse_lazy, reverse
|
||||
from django.http import Http404, JsonResponse
|
||||
|
||||
from django.http import HttpResponseRedirect, HttpResponse
|
||||
from reversion.views import RevisionMixin
|
||||
|
||||
from .models import Question, Category, Exam, CidUserAnswer
|
||||
|
||||
@@ -31,13 +32,15 @@ import json
|
||||
import statistics
|
||||
import plotly.express as px
|
||||
|
||||
from generic.views import ExamViews
|
||||
from generic.views import ExamCloneMixin, ExamViews, GenericViewBase
|
||||
|
||||
from rest_framework import viewsets, permissions
|
||||
from rest_framework.pagination import PageNumberPagination
|
||||
|
||||
from django.core.exceptions import PermissionDenied
|
||||
|
||||
from .forms import ExamForm
|
||||
|
||||
class AuthorOrCheckerRequiredMixin(object):
|
||||
def get_object(self, *args, **kwargs):
|
||||
obj = super().get_object(*args, **kwargs)
|
||||
@@ -253,9 +256,9 @@ def loadJsonAnswer(answer):
|
||||
return False, JsonResponse({"success": False, "error": "invalid"})
|
||||
|
||||
# The model should catch invalid data but this should be less intensive
|
||||
max_int = 10000000
|
||||
if answer["cid"] > max_int or answer["eid"] > max_int:
|
||||
return False, JsonResponse({"success": False})
|
||||
#max_int = 10000000
|
||||
#if answer["cid"] > max_int or answer["eid"] > max_int:
|
||||
# return False, JsonResponse({"success": False})
|
||||
|
||||
exam = get_object_or_404(Exam, pk=answer["eid"])
|
||||
|
||||
@@ -303,4 +306,20 @@ def loadJsonAnswer(answer):
|
||||
|
||||
return True, None
|
||||
|
||||
PhysicsExamViews = ExamViews(Exam, Question, "physics", "physics", loadJsonAnswer)
|
||||
PhysicsExamViews = ExamViews(Exam, Question, "physics", "physics", loadJsonAnswer)
|
||||
|
||||
GenericViews = GenericViewBase("physics", Question, CidUserAnswer, Exam)
|
||||
|
||||
class ExamCreate(RevisionMixin, LoginRequiredMixin, CreateView):
|
||||
model = Exam
|
||||
form_class = ExamForm
|
||||
|
||||
def form_valid(self, form):
|
||||
self.object = form.save(commit=False)
|
||||
self.object.save()
|
||||
|
||||
form.instance.author.add(self.request.user.id)
|
||||
return super().form_valid(form)
|
||||
|
||||
class ExamClone(ExamCloneMixin, ExamCreate):
|
||||
"""Clone exam view"""
|
||||
Reference in New Issue
Block a user