.
This commit is contained in:
+37
-45
@@ -34,8 +34,7 @@ import plotly.express as px
|
|||||||
|
|
||||||
def question_list(request):
|
def question_list(request):
|
||||||
questions = Question.objects.all()
|
questions = Question.objects.all()
|
||||||
return render(request, "physics/question_list.html",
|
return render(request, "physics/question_list.html", {"questions": questions})
|
||||||
{"questions": questions})
|
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@@ -47,8 +46,7 @@ def index(request):
|
|||||||
@login_required
|
@login_required
|
||||||
def question_detail(request, pk):
|
def question_detail(request, pk):
|
||||||
question = get_object_or_404(Question, pk=pk)
|
question = get_object_or_404(Question, pk=pk)
|
||||||
return render(request, "physics/question_detail.html",
|
return render(request, "physics/question_detail.html", {"question": question})
|
||||||
{"question": question})
|
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@@ -73,40 +71,40 @@ def exam_overview(request, pk):
|
|||||||
return render(
|
return render(
|
||||||
request,
|
request,
|
||||||
"physics/exam_overview.html",
|
"physics/exam_overview.html",
|
||||||
{
|
{"exam": exam, "questions": questions, "question_number": question_number},
|
||||||
"exam": exam,
|
|
||||||
"questions": questions,
|
|
||||||
"question_number": question_number
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def exam_toggle_results_published(request, pk):
|
def exam_toggle_results_published(request, pk):
|
||||||
if request.is_ajax() and request.method=='POST':
|
if request.is_ajax() and request.method == "POST":
|
||||||
|
|
||||||
exam = get_object_or_404(Exam, pk=pk)
|
exam = get_object_or_404(Exam, pk=pk)
|
||||||
|
|
||||||
exam.publish_results = True if request.POST.get('publish_results') == 'true' else False
|
exam.publish_results = (
|
||||||
|
True if request.POST.get("publish_results") == "true" else False
|
||||||
|
)
|
||||||
exam.save()
|
exam.save()
|
||||||
data = {'status':'success', 'publish_results':exam.publish_results}
|
data = {"status": "success", "publish_results": exam.publish_results}
|
||||||
return JsonResponse(data, status=200)
|
return JsonResponse(data, status=200)
|
||||||
else:
|
else:
|
||||||
data = {'status':'error'}
|
data = {"status": "error"}
|
||||||
return JsonResponse(data, status=400)
|
return JsonResponse(data, status=400)
|
||||||
|
|
||||||
|
|
||||||
def exam_toggle_active(request, pk):
|
def exam_toggle_active(request, pk):
|
||||||
if request.is_ajax() and request.method=='POST':
|
if request.is_ajax() and request.method == "POST":
|
||||||
|
|
||||||
exam = get_object_or_404(Exam, pk=pk)
|
exam = get_object_or_404(Exam, pk=pk)
|
||||||
|
|
||||||
exam.active = True if request.POST.get('active') == 'true' else False
|
exam.active = True if request.POST.get("active") == "true" else False
|
||||||
exam.save()
|
exam.save()
|
||||||
data = {'status':'success', 'active':exam.active}
|
data = {"status": "success", "active": exam.active}
|
||||||
return JsonResponse(data, status=200)
|
return JsonResponse(data, status=200)
|
||||||
else:
|
else:
|
||||||
data = {'status':'error'}
|
data = {"status": "error"}
|
||||||
return JsonResponse(data, status=400)
|
return JsonResponse(data, status=400)
|
||||||
|
|
||||||
|
|
||||||
def active_exams(request):
|
def active_exams(request):
|
||||||
exams = Exam.objects.all()
|
exams = Exam.objects.all()
|
||||||
print(exams)
|
print(exams)
|
||||||
@@ -119,15 +117,18 @@ def active_exams(request):
|
|||||||
return render(request, "physics/available_exam_list.html", {"exams": active_exams})
|
return render(request, "physics/available_exam_list.html", {"exams": active_exams})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def exam_scores_cid(request, pk):
|
def exam_scores_cid(request, pk):
|
||||||
exam = get_object_or_404(Exam, pk=pk)
|
exam = get_object_or_404(Exam, pk=pk)
|
||||||
|
|
||||||
questions = exam.exam_questions.all()
|
questions = exam.exam_questions.all()
|
||||||
|
|
||||||
cids = (CidUserAnswer.objects.filter(question__in=questions).values_list(
|
cids = (
|
||||||
"cid", flat=True).distinct())
|
CidUserAnswer.objects.filter(question__in=questions)
|
||||||
|
.order_by("cid")
|
||||||
|
.values_list("cid", flat=True)
|
||||||
|
.distinct()
|
||||||
|
)
|
||||||
|
|
||||||
cids = cids.sort()
|
cids = cids.sort()
|
||||||
|
|
||||||
@@ -184,7 +185,14 @@ def exam_scores_cid(request, pk):
|
|||||||
mode = "No unique mode"
|
mode = "No unique mode"
|
||||||
|
|
||||||
df = user_scores_list
|
df = user_scores_list
|
||||||
fig = px.histogram(df, x=0, title="Distribution of scores", labels={"0": "Score"}, height=400, width=600)
|
fig = px.histogram(
|
||||||
|
df,
|
||||||
|
x=0,
|
||||||
|
title="Distribution of scores",
|
||||||
|
labels={"0": "Score"},
|
||||||
|
height=400,
|
||||||
|
width=600,
|
||||||
|
)
|
||||||
fig_html = fig.to_html()
|
fig_html = fig.to_html()
|
||||||
|
|
||||||
max_score = len(questions)
|
max_score = len(questions)
|
||||||
@@ -212,6 +220,7 @@ def exam_scores_cid(request, pk):
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def exam_scores_cid_user(request, pk, sk):
|
def exam_scores_cid_user(request, pk, sk):
|
||||||
exam = get_object_or_404(Exam, pk=pk)
|
exam = get_object_or_404(Exam, pk=pk)
|
||||||
|
|
||||||
@@ -224,7 +233,6 @@ def exam_scores_cid_user(request, pk, sk):
|
|||||||
answers_marks = []
|
answers_marks = []
|
||||||
answers = []
|
answers = []
|
||||||
|
|
||||||
|
|
||||||
for q in questions:
|
for q in questions:
|
||||||
# Get user answer
|
# Get user answer
|
||||||
user_answer = q.cid_user_answers.filter(cid=cid).first()
|
user_answer = q.cid_user_answers.filter(cid=cid).first()
|
||||||
@@ -305,9 +313,7 @@ def postExamAnswers(request):
|
|||||||
|
|
||||||
def loadJsonAnswer(answer):
|
def loadJsonAnswer(answer):
|
||||||
# As access is not restricted make sure the data appears valid
|
# As access is not restricted make sure the data appears valid
|
||||||
if (not isinstance(answer["cid"],
|
if (not isinstance(answer["cid"], int)) or (not isinstance(answer["eid"], int)):
|
||||||
int)) or (not isinstance(answer["eid"], int)
|
|
||||||
):
|
|
||||||
return JsonResponse({"success": False, "error": "invalid"})
|
return JsonResponse({"success": False, "error": "invalid"})
|
||||||
|
|
||||||
# The model should catch invalid data but this should be less intensive
|
# The model should catch invalid data but this should be less intensive
|
||||||
@@ -318,10 +324,9 @@ def loadJsonAnswer(answer):
|
|||||||
exam = get_object_or_404(Exam, pk=answer["eid"])
|
exam = get_object_or_404(Exam, pk=answer["eid"])
|
||||||
|
|
||||||
if not exam.active:
|
if not exam.active:
|
||||||
return JsonResponse({
|
return JsonResponse(
|
||||||
"success": False,
|
{"success": False, "error": "No active exam: {}".format(answer["eid"])}
|
||||||
"error": "No active exam: {}".format(answer["eid"])
|
)
|
||||||
})
|
|
||||||
|
|
||||||
questions = defaultdict(dict)
|
questions = defaultdict(dict)
|
||||||
|
|
||||||
@@ -329,11 +334,10 @@ def loadJsonAnswer(answer):
|
|||||||
questions[q][n] = a
|
questions[q][n] = a
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
for qid in questions:
|
for qid in questions:
|
||||||
exiting_answers = CidUserAnswer.objects.filter(question__id=qid,
|
exiting_answers = CidUserAnswer.objects.filter(
|
||||||
exam__id=answer["eid"],
|
question__id=qid, exam__id=answer["eid"], cid=answer["cid"]
|
||||||
cid=answer["cid"])
|
)
|
||||||
|
|
||||||
a = questions[qid]["a"]
|
a = questions[qid]["a"]
|
||||||
b = questions[qid]["b"]
|
b = questions[qid]["b"]
|
||||||
@@ -362,15 +366,3 @@ def loadJsonAnswer(answer):
|
|||||||
ans.save()
|
ans.save()
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user