.
This commit is contained in:
@@ -60,6 +60,7 @@ urlpatterns = [
|
|||||||
path("feedback/note/<int:pk>/complete", views.feedback_mark_complete, name="feedback_mark_complete"),
|
path("feedback/note/<int:pk>/complete", views.feedback_mark_complete, name="feedback_mark_complete"),
|
||||||
#path("feedback/", views.AddQuestionNote.as_view(), name="feedback"),
|
#path("feedback/", views.AddQuestionNote.as_view(), name="feedback"),
|
||||||
path("feedback/answer", views.answer_suggestion_submit, name="answer_suggestion_submit"),
|
path("feedback/answer", views.answer_suggestion_submit, name="answer_suggestion_submit"),
|
||||||
|
path("feedback/answer_submit", views.answer_submit, name="answer_submit"),
|
||||||
path("feedback/answer/confirm", views.answer_suggestion_confirm, name="answer_suggestion_confirm"),
|
path("feedback/answer/confirm", views.answer_suggestion_confirm, name="answer_suggestion_confirm"),
|
||||||
path("feedback/view", views.view_feedback, name="view_feedback"),
|
path("feedback/view", views.view_feedback, name="view_feedback"),
|
||||||
|
|
||||||
|
|||||||
@@ -248,6 +248,37 @@ def answer_suggestion_submit(request):
|
|||||||
# postExamAnswers
|
# postExamAnswers
|
||||||
return JsonResponse({"success": False, "error": "Invalid data"})
|
return JsonResponse({"success": False, "error": "Invalid data"})
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
def answer_submit(request):
|
||||||
|
if request.is_ajax and request.method == "POST":
|
||||||
|
post_data = json.loads(request.body)
|
||||||
|
qid = post_data["qid"]
|
||||||
|
question_type = post_data["question_type"]
|
||||||
|
answer_string = post_data["answer"]
|
||||||
|
status = post_data["status"]
|
||||||
|
|
||||||
|
if str(status) not in "012":
|
||||||
|
return JsonResponse({"success": False, "error": "Invalid status"})
|
||||||
|
|
||||||
|
if question_type == "anatomy":
|
||||||
|
AnswerModel = AnatomyAnswer
|
||||||
|
question = AnatomyQuestion
|
||||||
|
elif question_type == "rapid":
|
||||||
|
AnswerModel = RapidAnswer
|
||||||
|
question = Rapid
|
||||||
|
else:
|
||||||
|
return JsonResponse({"success": False, "error": "Invalid question type"})
|
||||||
|
|
||||||
|
q = get_object_or_404(question, pk=qid)
|
||||||
|
if AnswerModel.objects.filter(answer=answer_string, question=q):
|
||||||
|
return JsonResponse({"success": False, "error": "Answer already exists"})
|
||||||
|
|
||||||
|
|
||||||
|
a = AnswerModel(question=q, answer=answer_string, status=status)
|
||||||
|
a.save()
|
||||||
|
|
||||||
|
return JsonResponse({"success": False, "error": "Invalid data"})
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def answer_suggestion_confirm(request):
|
def answer_suggestion_confirm(request):
|
||||||
if request.is_ajax and request.method == "POST":
|
if request.is_ajax and request.method == "POST":
|
||||||
|
|||||||
@@ -312,6 +312,7 @@ class Rapid(models.Model):
|
|||||||
for r in self.region.all():
|
for r in self.region.all():
|
||||||
for a in self.abnormality.all():
|
for a in self.abnormality.all():
|
||||||
answers.append("{} {}".format(r.name, a.name))
|
answers.append("{} {}".format(r.name, a.name))
|
||||||
|
answers.append("{} {}".format(a.name, r.name))
|
||||||
|
|
||||||
compare_answers = self.get_compare_answers()
|
compare_answers = self.get_compare_answers()
|
||||||
|
|
||||||
|
|||||||
@@ -11,8 +11,9 @@
|
|||||||
<div class="pre-whitespace multi-image-block"><b>Images:</b>
|
<div class="pre-whitespace multi-image-block"><b>Images:</b>
|
||||||
{% for image in question.images.all %}
|
{% for image in question.images.all %}
|
||||||
<span class="image-block">
|
<span class="image-block">
|
||||||
Image {{ forloop.counter }}{% if image.feedback_image %} [feedback image]{% endif %}:
|
Image {{ forloop.counter }}{% if image.feedback_image %} [feedback image]{% endif %}:
|
||||||
<div class="dicom-image rapid-img {% if image.feedback_image %}feedback-img{% endif %}" data-url="https://penracourses.org.uk{{ image.image.url}}"></div>
|
<div class="dicom-image rapid-img {% if image.feedback_image %}feedback-img{% endif %}"
|
||||||
|
data-url="https://penracourses.org.uk{{ image.image.url}}"></div>
|
||||||
</span>
|
</span>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
@@ -29,11 +30,12 @@
|
|||||||
href="{% url 'rapids:verified_detail' pk=verified.pk %}">{{verified}}</a>, {% endfor %}</p>
|
href="{% url 'rapids:verified_detail' pk=verified.pk %}">{{verified}}</a>, {% endfor %}</p>
|
||||||
<p><b>Scrapped:</b> {{ question.scrapped }} <a href="{% url 'rapids:rapid_scrap' pk=question.pk %}">(toggle)</a>
|
<p><b>Scrapped:</b> {{ question.scrapped }} <a href="{% url 'rapids:rapid_scrap' pk=question.pk %}">(toggle)</a>
|
||||||
<p class="pre-whitespace">
|
<p class="pre-whitespace">
|
||||||
Answers (score): {% for answer in question.answers.all %}
|
Answers (score): {% for answer in question.answers.all %}
|
||||||
<span {% if answer.proposed %}class="proposed-answer" data-aid="{{answer.pk}}" data-question-type="rapid" {% endif %}>
|
<span {% if answer.proposed %}class="proposed-answer" data-aid="{{answer.pk}}" data-question-type="rapid" {%
|
||||||
{{ answer }} ({{answer.status}}),
|
endif %}>
|
||||||
</span>
|
{{ answer }} ({{answer.status}}),
|
||||||
{% endfor %}
|
</span>
|
||||||
|
{% endfor %}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
@@ -51,97 +53,136 @@
|
|||||||
<ul class="notes">
|
<ul class="notes">
|
||||||
{% for note in question.anon_notes.all %}
|
{% for note in question.anon_notes.all %}
|
||||||
<li {% if note.complete %}class='complete' {% endif %}>
|
<li {% if note.complete %}class='complete' {% endif %}>
|
||||||
{{ note.created_on }} by {{ note.author }}: {{note.note_type}} / {{ note.note }}
|
{{ note.created_on }} by {{ note.author }}: {{note.note_type}} / {{ note.note }}
|
||||||
{% if not note.complete %}
|
{% if not note.complete %}
|
||||||
(<a href="{% url 'feedback_mark_complete' pk=note.pk %}">Mark complete</a>)
|
(<a href="{% url 'feedback_mark_complete' pk=note.pk %}">Mark complete</a>)
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</li>
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<detail>
|
<details>
|
||||||
<summary><h3>Suggested answers</h3></summary>
|
<summary>
|
||||||
<ul>
|
<h3>Suggested answers</h3>
|
||||||
{% for ans in question.get_suggested_answers %}
|
</summary>
|
||||||
<li>{{ans}}</li>
|
<ul class="suggested_answers">
|
||||||
{% endfor %}
|
{% for ans in question.get_suggested_answers %}
|
||||||
|
<li data-string="{{ans}}">{{ans}}</li>
|
||||||
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
|
</div>
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>
|
||||||
|
<h3>Image viewer</h3>
|
||||||
|
</summary>
|
||||||
|
<div id="single-dicom-viewer" class="dicom-viewer" data-images="{{ question.get_image_urls }}" data-annotations=''>
|
||||||
</div>
|
</div>
|
||||||
</detail>
|
</detail>
|
||||||
|
|
||||||
<detail>
|
<script>
|
||||||
<summary><h3>Image viewer</h3></summary>
|
$(document).ready(function () {
|
||||||
<div id="single-dicom-viewer" class="dicom-viewer" data-images="{{ question.get_image_urls }}" data-annotations=''></div>
|
|
||||||
</div>
|
|
||||||
</detail>
|
|
||||||
|
|
||||||
<script>
|
$(".suggested_answers li").each((n, el) => {
|
||||||
$(document).ready(function () {
|
$(el).append($("<span class='confirm'>[Correct]</span>").on("click", function () {
|
||||||
// send request to change the is_private state on customSwitches toggle
|
$.ajax({
|
||||||
$(".proposed-answer").each((n, el) => {
|
url: "{% url 'answer_submit' %}",
|
||||||
|
data: {
|
||||||
|
csrfmiddlewaretoken: "{{ csrf_token }}",
|
||||||
|
//active: this.checked // true if checked else false
|
||||||
|
question_type: "rapid",
|
||||||
|
qid: "{{question.pk}}",
|
||||||
|
status: 2,
|
||||||
|
answer: el.dataset.string,
|
||||||
|
},
|
||||||
|
type: "POST",
|
||||||
|
dataType: "json",
|
||||||
|
})
|
||||||
|
// $.ajax().done(), $.ajax().fail(), $ajax().always() are upto you. Add/change accordingly
|
||||||
|
.done(function (data) {
|
||||||
|
console.log(data);
|
||||||
|
|
||||||
// Add button to confirm answer is correct
|
if (data.success) {
|
||||||
$(el).append($("<span class='confirm'>[Correct]</span>").on("click", function () {
|
toastr.info('Answer saved')
|
||||||
$.ajax({
|
$(el).find(".confirm").remove()
|
||||||
url: "{% url 'answer_suggestion_confirm' %}",
|
$(el).removeClass("proposed-answer")
|
||||||
data: {
|
}
|
||||||
csrfmiddlewaretoken: "{{ csrf_token }}",
|
// show some message according to the response.
|
||||||
//active: this.checked // true if checked else false
|
// For eg. A message box showing that the status has been changed
|
||||||
question_type: "rapid",
|
})
|
||||||
aid: el.dataset.aid,
|
.always(function () {
|
||||||
status: 2,
|
console.log('[Done]');
|
||||||
},
|
})
|
||||||
type: "POST",
|
}))
|
||||||
dataType: "json",
|
|
||||||
})
|
|
||||||
// $.ajax().done(), $.ajax().fail(), $ajax().always() are upto you. Add/change accordingly
|
|
||||||
.done(function (data) {
|
|
||||||
console.log(data);
|
|
||||||
|
|
||||||
if (data.success) {
|
});
|
||||||
toastr.info('Answer saved')
|
|
||||||
$(el).find(".confirm").remove()
|
|
||||||
$(el).removeClass("proposed-answer")
|
|
||||||
}
|
|
||||||
// show some message according to the response.
|
|
||||||
// For eg. A message box showing that the status has been changed
|
|
||||||
})
|
|
||||||
.always(function () {
|
|
||||||
console.log('[Done]');
|
|
||||||
})
|
|
||||||
}))
|
|
||||||
|
|
||||||
// Add button to confirm answer is incorrect
|
// send request to change the is_private state on customSwitches toggle
|
||||||
$(el).append($("<span class='confirm'>[Incorrect]</span>").on("click", function () {
|
$(".proposed-answer").each((n, el) => {
|
||||||
$.ajax({
|
|
||||||
url: "{% url 'answer_suggestion_confirm' %}",
|
|
||||||
data: {
|
|
||||||
csrfmiddlewaretoken: "{{ csrf_token }}",
|
|
||||||
//active: this.checked // true if checked else false
|
|
||||||
question_type: "rapid",
|
|
||||||
aid: el.dataset.aid,
|
|
||||||
status: 0,
|
|
||||||
},
|
|
||||||
type: "POST",
|
|
||||||
dataType: "json",
|
|
||||||
})
|
|
||||||
// $.ajax().done(), $.ajax().fail(), $ajax().always() are upto you. Add/change accordingly
|
|
||||||
.done(function (data) {
|
|
||||||
console.log(data);
|
|
||||||
|
|
||||||
if (data.success) {
|
// Add button to confirm answer is correct
|
||||||
toastr.info('Answer saved')
|
$(el).append($("<span class='confirm'>[Correct]</span>").on("click", function () {
|
||||||
$(el).find(".confirm").remove()
|
$.ajax({
|
||||||
$(el).removeClass("proposed-answer")
|
url: "{% url 'answer_suggestion_confirm' %}",
|
||||||
}
|
data: {
|
||||||
// show some message according to the response.
|
csrfmiddlewaretoken: "{{ csrf_token }}",
|
||||||
// For eg. A message box showing that the status has been changed
|
//active: this.checked // true if checked else false
|
||||||
})
|
question_type: "rapid",
|
||||||
.always(function () {
|
aid: el.dataset.aid,
|
||||||
console.log('[Done]');
|
status: 2,
|
||||||
})
|
},
|
||||||
}))
|
type: "POST",
|
||||||
});
|
dataType: "json",
|
||||||
});
|
})
|
||||||
|
// $.ajax().done(), $.ajax().fail(), $ajax().always() are upto you. Add/change accordingly
|
||||||
|
.done(function (data) {
|
||||||
|
console.log(data);
|
||||||
|
|
||||||
</script>
|
if (data.success) {
|
||||||
|
toastr.info('Answer saved')
|
||||||
|
$(el).find(".confirm").remove()
|
||||||
|
$(el).removeClass("proposed-answer")
|
||||||
|
}
|
||||||
|
// show some message according to the response.
|
||||||
|
// For eg. A message box showing that the status has been changed
|
||||||
|
})
|
||||||
|
.always(function () {
|
||||||
|
console.log('[Done]');
|
||||||
|
})
|
||||||
|
}))
|
||||||
|
|
||||||
|
// Add button to confirm answer is incorrect
|
||||||
|
$(el).append($("<span class='confirm'>[Incorrect]</span>").on("click", function () {
|
||||||
|
$.ajax({
|
||||||
|
url: "{% url 'answer_suggestion_confirm' %}",
|
||||||
|
data: {
|
||||||
|
csrfmiddlewaretoken: "{{ csrf_token }}",
|
||||||
|
//active: this.checked // true if checked else false
|
||||||
|
question_type: "rapid",
|
||||||
|
aid: el.dataset.aid,
|
||||||
|
status: 0,
|
||||||
|
},
|
||||||
|
type: "POST",
|
||||||
|
dataType: "json",
|
||||||
|
})
|
||||||
|
// $.ajax().done(), $.ajax().fail(), $ajax().always() are upto you. Add/change accordingly
|
||||||
|
.done(function (data) {
|
||||||
|
console.log(data);
|
||||||
|
|
||||||
|
if (data.success) {
|
||||||
|
toastr.info('Answer saved')
|
||||||
|
$(el).find(".confirm").remove()
|
||||||
|
$(el).removeClass("proposed-answer")
|
||||||
|
}
|
||||||
|
// show some message according to the response.
|
||||||
|
// For eg. A message box showing that the status has been changed
|
||||||
|
})
|
||||||
|
.always(function () {
|
||||||
|
console.log('[Done]');
|
||||||
|
})
|
||||||
|
}))
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
</script>
|
||||||
Reference in New Issue
Block a user