.
This commit is contained in:
@@ -32,6 +32,8 @@
|
|||||||
</ol>
|
</ol>
|
||||||
<a href="{% url 'anatomy:exam_json' pk=exam.pk %}">JSON</a>
|
<a href="{% url 'anatomy:exam_json' pk=exam.pk %}">JSON</a>
|
||||||
<a href="{% url 'anatomy:exam_json_recreate' pk=exam.pk %}">Refresh JSON cache</a>
|
<a href="{% url 'anatomy:exam_json_recreate' pk=exam.pk %}">Refresh JSON cache</a>
|
||||||
|
<button id='button-open-access'>Make questions open access</button>
|
||||||
|
<button id='button-closed-access'>Make questions closed access</button>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
@@ -85,6 +87,50 @@
|
|||||||
console.log('[Done]');
|
console.log('[Done]');
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
$("#button-open-access").click(function () {
|
||||||
|
$.ajax({
|
||||||
|
url: "{% url 'anatomy:exam_json_edit' pk=exam.pk %}",
|
||||||
|
data: {
|
||||||
|
csrfmiddlewaretoken: "{{ csrf_token }}",
|
||||||
|
set_open_access: true,
|
||||||
|
},
|
||||||
|
type: "POST",
|
||||||
|
dataType: "json",
|
||||||
|
})
|
||||||
|
// $.ajax().done(), $.ajax().fail(), $ajax().always() are upto you. Add/change accordingly
|
||||||
|
.done(function (data) {
|
||||||
|
console.log(data);
|
||||||
|
|
||||||
|
if (data.status == "success") {
|
||||||
|
toastr.info('Question access state changed.')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.always(function () {
|
||||||
|
console.log('[Done]');
|
||||||
|
})
|
||||||
|
})
|
||||||
|
$("#button-closed-access").click(function () {
|
||||||
|
$.ajax({
|
||||||
|
url: "{% url 'anatomy:exam_json_edit' pk=exam.pk %}",
|
||||||
|
data: {
|
||||||
|
csrfmiddlewaretoken: "{{ csrf_token }}",
|
||||||
|
set_open_access: false,
|
||||||
|
},
|
||||||
|
type: "POST",
|
||||||
|
dataType: "json",
|
||||||
|
})
|
||||||
|
// $.ajax().done(), $.ajax().fail(), $ajax().always() are upto you. Add/change accordingly
|
||||||
|
.done(function (data) {
|
||||||
|
console.log(data);
|
||||||
|
|
||||||
|
if (data.status == "success") {
|
||||||
|
toastr.info('Question access state changed.')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.always(function () {
|
||||||
|
console.log('[Done]');
|
||||||
|
})
|
||||||
|
})
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
+11
-28
@@ -317,38 +317,21 @@ def loadJsonAnswer(answer):
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def exam_json_edit(request):
|
def exam_json_edit(request, pk):
|
||||||
if request.is_ajax and request.method == "POST":
|
if request.is_ajax() and request.method == "POST":
|
||||||
|
|
||||||
n = 0
|
exam = get_object_or_404(Exam, pk=pk)
|
||||||
# horrible but it works
|
|
||||||
for k in request.POST.dict():
|
|
||||||
print(k)
|
|
||||||
for answer in json.loads(k):
|
|
||||||
if not "exam" in answer:
|
|
||||||
return JsonResponse({"success": False})
|
|
||||||
|
|
||||||
exam = get_object_or_404(answer["exam"])
|
for q in exam.exam_questions.all():
|
||||||
|
q.open_acess = request.POST.get("set_open_access")
|
||||||
|
q.save()
|
||||||
|
|
||||||
if "set_open_access" in answer:
|
data = {"status": "success"}
|
||||||
#answer["set_open_access"]
|
return JsonResponse(data, status=200)
|
||||||
for q in exam.exam_questions.all():
|
else:
|
||||||
q.open_acess = answer["set_open_access"]
|
data = {"status": "error"}
|
||||||
q.save()
|
return JsonResponse(data, status=400)
|
||||||
|
|
||||||
|
|
||||||
return JsonResponse({"success": True})
|
|
||||||
|
|
||||||
|
|
||||||
if ret is not True:
|
|
||||||
return ret
|
|
||||||
n = n + 1
|
|
||||||
|
|
||||||
# print(UserAnswer.objects.filter(exam__id=q["eid"]))
|
|
||||||
# print(request.urlencode())
|
|
||||||
|
|
||||||
return JsonResponse({"success": True, "question_count": n})
|
|
||||||
return JsonResponse({"success": False, "error": "Invalid data"})
|
|
||||||
|
|
||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
def postExamAnswers(request):
|
def postExamAnswers(request):
|
||||||
|
|||||||
+1
-1
@@ -2,7 +2,7 @@
|
|||||||
<html>
|
<html>
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<title>Penra Courses</title>
|
<title>PENRA Courses</title>
|
||||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" />
|
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" />
|
||||||
<link rel="stylesheet" href="{% static 'css/anatomy.css' %}">
|
<link rel="stylesheet" href="{% static 'css/anatomy.css' %}">
|
||||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
|
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="anatomy">
|
<div class="anatomy">
|
||||||
<h1>Penra Courses</h1>
|
<h1>PENRA Courses</h1>
|
||||||
<a href="{% url 'anatomy:index'%}">Anatomy</a>
|
<a href="{% url 'anatomy:index'%}">Anatomy</a>
|
||||||
<a href="{% url 'physics:index'%}">Physics</a>
|
<a href="{% url 'physics:index'%}">Physics</a>
|
||||||
<a href="{% url 'login'%}">Log in</a>
|
<a href="{% url 'login'%}">Log in</a>
|
||||||
|
|||||||
Reference in New Issue
Block a user