Merge ssh://penracourses.org.uk:/home/django/rad
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import json
|
||||
from django.contrib.contenttypes.fields import GenericRelation
|
||||
from django.db import models
|
||||
from django.utils import timezone
|
||||
@@ -256,6 +257,15 @@ class AnatomyQuestion(models.Model):
|
||||
|
||||
return json
|
||||
|
||||
def get_image_url(self):
|
||||
return "https://www.penracourses.org.uk{}".format(self.image.url)
|
||||
|
||||
def get_image_url_array(self):
|
||||
return json.dumps(["https://www.penracourses.org.uk{}".format(self.image.url)])
|
||||
|
||||
def get_image_annotations(self):
|
||||
return json.dumps([self.image_annotations])
|
||||
|
||||
|
||||
@reversion.register
|
||||
class Answer(models.Model):
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
<form method="post">{% csrf_token %}
|
||||
<p>Are you sure you want to delete "{{ object }}"?</p>
|
||||
<input type="submit" value="Confirm">
|
||||
</form>
|
||||
@@ -5,7 +5,7 @@
|
||||
<a href="{% url 'anatomy:question_detail' question.id %}" title="View the Question">View</a> <a href="{% url 'anatomy:anatomy_question_update' question.id %}" title="Edit the Question">Edit</a> <a href="{% url 'admin:anatomy_anatomyquestion_change' question.id %}" title="Edit the Question using the admin interface">Admin Edit</a>
|
||||
<h3>{{ question.question_type }}</h3>
|
||||
|
||||
<div id="single-dicom-viewer" class="marking-dicom" data-images="https://www.penracourses.org.uk{{ question.image.url}}" data-annotations='{{question.get_annotations}}'>
|
||||
<div id="single-dicom-viewer" class="marking-dicom" data-images="{{ question.get_image_url_array }}" data-annotations='{{question.get_image_annotations}}'>
|
||||
</div>
|
||||
<div class="marking">
|
||||
<form method="POST" class="post-form">{% csrf_token %}
|
||||
|
||||
@@ -10,21 +10,23 @@
|
||||
<a href="{% url 'anatomy:question_clone' question.id %}" title="Clone the Question">Clone</a>
|
||||
<a href="{% url 'anatomy:question_delete' pk=question.pk %}" title="Delete the Question">Delete</a>
|
||||
<a href="{% url 'anatomy:question_delete' pk=question.pk %}" title="Delete the Question">Delete</a>
|
||||
<a href="#" onclick="return window.create_popup_window('{% url 'feedback_create' question_type='anatomy' pk=question.pk %}')"> Add Note</a>
|
||||
<a href="#"
|
||||
onclick="return window.create_popup_window('{% url 'feedback_create' question_type='anatomy' pk=question.pk %}')">
|
||||
Add Note</a>
|
||||
<a href="{% url 'admin:anatomy_anatomyquestion_change' question.id %}"
|
||||
title="Edit the Question using the admin interface">Admin Edit</a>
|
||||
{% if exam %}
|
||||
<div>
|
||||
{% if exam %}
|
||||
<div>
|
||||
|
||||
{% if previous > -1 %}
|
||||
<a href="{% url 'anatomy:exam_question_detail' exam.id previous %}">Previous question</a>
|
||||
{% if previous > -1 %}
|
||||
<a href="{% url 'anatomy:exam_question_detail' exam.id previous %}">Previous question</a>
|
||||
{% endif %}
|
||||
Viewing question as part of exam: {{exam.name}} [{{pos}}/{{exam_length}}]
|
||||
{% if next %}
|
||||
<a href="{% url 'anatomy:exam_question_detail' exam.id next %}">Next question</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
Viewing question as part of exam: {{exam.name}} [{{pos}}/{{exam_length}}]
|
||||
{% if next %}
|
||||
<a href="{% url 'anatomy:exam_question_detail' exam.id next %}">Next question</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
<button id="save-annotations">Save Annotations</button>
|
||||
<div id="dicom-image" class="dicom-image" data-url="https://www.penracourses.org.uk{{ question.image.url}}"
|
||||
@@ -68,33 +70,44 @@
|
||||
</div>
|
||||
{% include 'question_notes.html' %}
|
||||
<div>
|
||||
<span id="annotation-json-toggle">Annotation JSON (+/-):</span> <span id="annotation-json-content">
|
||||
<details>
|
||||
<summary>
|
||||
<span id="annotation-json-toggle">Annotation JSON (+/-):</span> <span id="annotation-json-content">
|
||||
</summary>
|
||||
|
||||
{% if question.image_annotations %}
|
||||
<pre>{{ question.image_annotations }}</pre>
|
||||
</span>
|
||||
{% else %}
|
||||
No saved annotations.
|
||||
{% endif %}
|
||||
</span>
|
||||
</details>
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function () {
|
||||
|
||||
$("#annotation-json-toggle").click(() => { $("#annotation-json-content").toggle() });
|
||||
//$("#annotation-json-toggle").click(() => {
|
||||
// $("#annotation-json-content").toggle()
|
||||
//});
|
||||
|
||||
// send request to change the is_private state on customSwitches toggle
|
||||
$("#save-annotations").click(function () {
|
||||
json = getJsonToolStateNoId();
|
||||
$.ajax({
|
||||
url: "{% url 'anatomy:question_save_annotation' pk=question.pk %}",
|
||||
data: {
|
||||
csrfmiddlewaretoken: "{{ csrf_token }}",
|
||||
annotation: json,
|
||||
},
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
error: function(e) {
|
||||
url: "{% url 'anatomy:question_save_annotation' pk=question.pk %}",
|
||||
data: {
|
||||
csrfmiddlewaretoken: "{{ csrf_token }}",
|
||||
annotation: json,
|
||||
},
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
error: function (e) {
|
||||
toastr.warning(`Error saving annotations`)
|
||||
console.log(e);
|
||||
},
|
||||
|
||||
})
|
||||
|
||||
})
|
||||
// $.ajax().done(), $.ajax().fail(), $ajax().always() are upto you. Add/change accordingly
|
||||
.done(function (data) {
|
||||
console.log(data);
|
||||
@@ -129,7 +142,5 @@
|
||||
return json_tool_state;
|
||||
|
||||
}
|
||||
|
||||
|
||||
</script>
|
||||
{% endblock %}
|
||||
+32
-22
@@ -33,13 +33,13 @@ from .forms import (
|
||||
MarkAnatomyQuestionForm,
|
||||
AnatomyQuestionForm,
|
||||
StructureForm,
|
||||
ExamForm
|
||||
ExamForm,
|
||||
)
|
||||
from .models import (
|
||||
AnatomyQuestion,
|
||||
BodyPart,
|
||||
CidUserAnswer,
|
||||
#Examination,
|
||||
# Examination,
|
||||
Structure,
|
||||
Exam,
|
||||
Answer,
|
||||
@@ -84,6 +84,7 @@ class AuthorOrCheckerRequiredMixin(object):
|
||||
raise PermissionDenied() # or Http404
|
||||
return obj
|
||||
|
||||
|
||||
@register.filter
|
||||
def get_item(dictionary, key):
|
||||
return dictionary.get(key)
|
||||
@@ -96,18 +97,16 @@ def user_is_admin(user):
|
||||
return False
|
||||
|
||||
|
||||
|
||||
def question_list(request):
|
||||
questions = AnatomyQuestion.objects.all()
|
||||
|
||||
if not request.user.groups.filter(name="anatomy_checker").exists() :
|
||||
if not request.user.groups.filter(name="anatomy_checker").exists():
|
||||
questions = questions.filter(open_access=False)
|
||||
#raise PermissionDenied()
|
||||
# raise PermissionDenied()
|
||||
|
||||
return render(request, "anatomy/question_list.html", {"questions": questions})
|
||||
|
||||
|
||||
|
||||
@login_required
|
||||
def answer_question(request, pk):
|
||||
question = get_object_or_404(AnatomyQuestion, pk=pk)
|
||||
@@ -133,7 +132,6 @@ def answer_question(request, pk):
|
||||
)
|
||||
|
||||
|
||||
|
||||
@login_required
|
||||
def exam_take(request, pk, sk):
|
||||
"""
|
||||
@@ -228,7 +226,9 @@ def loadJsonAnswer(answer):
|
||||
if (not isinstance(answer["cid"], int)) or (
|
||||
not isinstance(eid, int) or (not isinstance(answer["ans"], str))
|
||||
):
|
||||
return False, JsonResponse({"success": False, "error": "cid or eid or answers not defined"})
|
||||
return False, JsonResponse(
|
||||
{"success": False, "error": "cid or eid or answers not defined"}
|
||||
)
|
||||
|
||||
# The model should catch invalid data but this should be less intensive
|
||||
max_int = 999999999999999999999
|
||||
@@ -237,7 +237,7 @@ def loadJsonAnswer(answer):
|
||||
|
||||
exam = get_object_or_404(Exam, pk=eid)
|
||||
|
||||
#if not exam.active:
|
||||
# if not exam.active:
|
||||
# return False, JsonResponse(
|
||||
# {"success": False, "error": "No active exam: {}".format(eid)}
|
||||
# )
|
||||
@@ -265,8 +265,8 @@ def loadJsonAnswer(answer):
|
||||
return True, None
|
||||
|
||||
|
||||
#@csrf_exempt
|
||||
#def postExamAnswers(request):
|
||||
# @csrf_exempt
|
||||
# def postExamAnswers(request):
|
||||
# if request.is_ajax and request.method == "POST":
|
||||
#
|
||||
# n = 0
|
||||
@@ -435,7 +435,6 @@ def mark(request, pk, sk):
|
||||
)
|
||||
|
||||
|
||||
|
||||
@login_required
|
||||
def exam_scores_cid(request, pk):
|
||||
exam = get_object_or_404(Exam, pk=pk)
|
||||
@@ -552,7 +551,6 @@ def exam_scores_cid_user(request, pk, sk):
|
||||
answers_marks = []
|
||||
answers = []
|
||||
|
||||
|
||||
view_all_results = False
|
||||
if request.user.groups.filter(name="view_all_results").exists():
|
||||
view_all_results = True
|
||||
@@ -696,7 +694,7 @@ class AnatomyQuestionCreateBase(RevisionMixin, LoginRequiredMixin, CreateView):
|
||||
|
||||
def get_form_kwargs(self):
|
||||
kwargs = super(AnatomyQuestionCreateBase, self).get_form_kwargs()
|
||||
kwargs.update({'user': self.request.user})
|
||||
kwargs.update({"user": self.request.user})
|
||||
return kwargs
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
@@ -801,7 +799,7 @@ class AnatomyQuestionUpdate(RevisionMixin, AuthorOrCheckerRequiredMixin, UpdateV
|
||||
|
||||
def get_form_kwargs(self):
|
||||
kwargs = super(AnatomyQuestionUpdate, self).get_form_kwargs()
|
||||
kwargs.update({'user': self.request.user})
|
||||
kwargs.update({"user": self.request.user})
|
||||
return kwargs
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
@@ -826,7 +824,6 @@ class AnatomyQuestionUpdate(RevisionMixin, AuthorOrCheckerRequiredMixin, UpdateV
|
||||
self.object = form.save(commit=False)
|
||||
self.object.save()
|
||||
|
||||
|
||||
form.instance.author.add(self.request.user.id)
|
||||
|
||||
context = self.get_context_data(form=form)
|
||||
@@ -949,6 +946,7 @@ class AnatomyQuestionView(LoginRequiredMixin, SingleTableMixin, FilterView):
|
||||
|
||||
filterset_class = AnatomyQuestionFilter
|
||||
|
||||
|
||||
@user_is_author_or_anatomy_checker
|
||||
def question_save_annotation(request, pk):
|
||||
if request.is_ajax() and request.method == "POST":
|
||||
@@ -965,11 +963,15 @@ def question_save_annotation(request, pk):
|
||||
return JsonResponse(data, status=400)
|
||||
|
||||
|
||||
AnatomyExamViews = ExamViews(Exam, AnatomyQuestion, "anatomy", "anatomy", loadJsonAnswer)
|
||||
AnatomyExamViews = ExamViews(
|
||||
Exam, AnatomyQuestion, "anatomy", "anatomy", loadJsonAnswer
|
||||
)
|
||||
|
||||
|
||||
class UserAnswerView(LoginRequiredMixin, DetailView):
|
||||
model = CidUserAnswer
|
||||
|
||||
|
||||
class UserAnswerTableView(LoginRequiredMixin, SingleTableMixin, FilterView):
|
||||
model = CidUserAnswer
|
||||
table_class = AnatomyUserAnswerTable
|
||||
@@ -978,16 +980,17 @@ class UserAnswerTableView(LoginRequiredMixin, SingleTableMixin, FilterView):
|
||||
filterset_class = AnatomyUserAnswerFilter
|
||||
|
||||
|
||||
|
||||
class UserAnswerDelete(SuperuserRequiredMixin, DeleteView):
|
||||
model = CidUserAnswer
|
||||
template_name = "user_answer_delete.html"
|
||||
success_url = reverse_lazy("anatomy:user_answer_table_view")
|
||||
|
||||
|
||||
class QuestionDelete(AuthorOrCheckerRequiredMixin, DeleteView):
|
||||
model = AnatomyQuestion
|
||||
success_url = reverse_lazy("anatomy:question_list")
|
||||
|
||||
|
||||
class ExamCreate(RevisionMixin, LoginRequiredMixin, CreateView):
|
||||
model = Exam
|
||||
form_class = ExamForm
|
||||
@@ -999,7 +1002,10 @@ class ExamCreate(RevisionMixin, LoginRequiredMixin, CreateView):
|
||||
form.instance.author.add(self.request.user.id)
|
||||
return super().form_valid(form)
|
||||
|
||||
class ExamUpdate(RevisionMixin, LoginRequiredMixin, AuthorOrCheckerRequiredMixin, UpdateView):
|
||||
|
||||
class ExamUpdate(
|
||||
RevisionMixin, LoginRequiredMixin, AuthorOrCheckerRequiredMixin, UpdateView
|
||||
):
|
||||
model = Exam
|
||||
form_class = ExamForm
|
||||
|
||||
@@ -1010,8 +1016,9 @@ class ExamUpdate(RevisionMixin, LoginRequiredMixin, AuthorOrCheckerRequiredMixin
|
||||
form.instance.author.add(self.request.user.id)
|
||||
return super().form_valid(form)
|
||||
|
||||
|
||||
class ExamViewSet(RevisionMixin, viewsets.ModelViewSet):
|
||||
#queryset = Exam.objects.all().order_by('name')
|
||||
# queryset = Exam.objects.all().order_by('name')
|
||||
serializer_class = ExamSerializer
|
||||
permission_classes = [permissions.IsAuthenticated]
|
||||
|
||||
@@ -1022,15 +1029,18 @@ class ExamViewSet(RevisionMixin, viewsets.ModelViewSet):
|
||||
user = self.request.user
|
||||
if user.groups.filter(name="rapid_checker").exists():
|
||||
return Exam.objects.all()
|
||||
|
||||
|
||||
return Exam.objects.filter(author__id=user.id)
|
||||
|
||||
|
||||
class ExamDelete(RevisionMixin, AuthorOrCheckerRequiredMixin, DeleteView):
|
||||
model = Exam
|
||||
template_name = "exam_confirm_delete.html"
|
||||
success_url = reverse_lazy("anatomy:index")
|
||||
|
||||
|
||||
GenericViews = GenericViewBase("anatomy", AnatomyQuestion, CidUserAnswer, Exam)
|
||||
|
||||
|
||||
class ExamClone(ExamCloneMixin, ExamCreate):
|
||||
"""Clone exam view"""
|
||||
"""Clone exam view"""
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
<form method="post">{% csrf_token %}
|
||||
<p>Are you sure you want to delete the exam "{{ object }}"?</p>
|
||||
<input type="submit" value="Confirm">
|
||||
<a href="{{ object.get_absolute_url }}" class="btn btn-default">Cancel</a>
|
||||
</form>
|
||||
{% endblock content %}
|
||||
|
||||
Reference in New Issue
Block a user