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