This commit is contained in:
Ross
2021-12-07 22:09:54 +00:00
parent 515d7b8d5d
commit 4b899780e5
3 changed files with 91 additions and 26 deletions
+19
View File
@@ -0,0 +1,19 @@
<div id="single-dicom-viewer" class="dicom-viewer" data-images=""
data-annotations=''>
</div>
<button class="previous-btn">Previous</button>
<button class="next-btn">Next</button>
{% for id in ids %}
{{id}}
{% endfor %}
<script>
$(document).ready(function () {
})
</script>
<style>
</style>
+7 -1
View File
@@ -17,7 +17,13 @@ urlpatterns = [
# path("verified/<int:pk>/", views.verified_detail, name="verified_detail"),
path(
"question/<int:pk>/", views.GenericViews.question_detail, name="question_detail"
), # path("question/<int:pk>/json", views.question_json, name="question_json"),
),
path("question/<int:pk>/json", views.question_json, name="question_json"),
path(
"question/<int:pk>/json/unbased",
views.question_json_unbased,
name="question_json_unbased",
),
path(
"question/<int:pk>/save_annotation",
views.question_save_annotation,
+65 -25
View File
@@ -102,9 +102,10 @@ def normaliseScore(score):
return 7.5
elif score in [60]:
return 8
return 4
class AuthorOrCheckerRequiredMixin(object):
def get_object(self, *args, **kwargs):
obj = super().get_object(*args, **kwargs)
@@ -114,6 +115,7 @@ class AuthorOrCheckerRequiredMixin(object):
raise PermissionDenied() # or Http404
return obj
@login_required
def rapid_split(request, pk):
rapid = get_object_or_404(Rapid, pk=pk)
@@ -129,7 +131,7 @@ def rapid_split(request, pk):
old_abnormality = rapid.abnormality.all()
old_region = rapid.region.all()
old_examination = rapid.examination.all()
#old_site = rapid.site.all()
# old_site = rapid.site.all()
old_author = rapid.author.all()
if not images:
@@ -143,7 +145,7 @@ def rapid_split(request, pk):
rapid.abnormality.set(old_abnormality)
rapid.region.set(old_region)
rapid.examination.set(old_examination)
#rapid.site.set(old_site)
# rapid.site.set(old_site)
rapid.author.set(old_author)
images[n].rapid = rapid
images[n].save()
@@ -157,8 +159,6 @@ def rapid_split(request, pk):
return render(request, "rapids/question_detail.html", {"question": rapid})
class RapidCreationDefaultView(LoginRequiredMixin, UpdateView):
model = RapidCreationDefault
form_class = RapidCreationDefaultForm
@@ -195,7 +195,6 @@ class RapidCreationDefaultView(LoginRequiredMixin, UpdateView):
# form.instance.author.add(self.request.user.id)
@login_required
def rapid_clone(request, pk):
new_item = get_object_or_404(Rapid, pk=pk)
@@ -526,7 +525,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)}
# )
@@ -573,10 +572,12 @@ def loadJsonAnswer(answer):
def mark_all(request, exam_pk, sk):
return mark(request, exam_pk, sk, unmarked_exam_answers_only=False)
@login_required
def mark_review(request, exam_pk, sk):
return mark(request, exam_pk, sk, unmarked_exam_answers_only=False, review=True)
# @user_passes_test(user_is_admin, login_url="/accounts/login")
@login_required
def mark(request, exam_pk, sk, unmarked_exam_answers_only=True, review=False):
@@ -605,7 +606,6 @@ def mark(request, exam_pk, sk, unmarked_exam_answers_only=True, review=False):
except IndexError:
raise Http404("Exam question does not exist")
if request.method == "POST":
form = MarkRapidQuestionForm(request.POST)
@@ -627,7 +627,7 @@ def mark(request, exam_pk, sk, unmarked_exam_answers_only=True, review=False):
("correct", Answer.MarkOptions.CORRECT),
("half-correct", Answer.MarkOptions.HALF_MARK),
("incorrect", Answer.MarkOptions.INCORRECT),
)
)
for status_string, status in to_run:
for ans in marked_answers[status_string]:
@@ -657,12 +657,11 @@ def mark(request, exam_pk, sk, unmarked_exam_answers_only=True, review=False):
else:
form = MarkRapidQuestionForm()
#answers_dict = {}
# answers_dict = {}
#for ans in question.answers.all():
# for ans in question.answers.all():
# answers_dict[ans.answer_compare] = ans
correct_answers = []
half_mark_answers = []
incorrect_answers = []
@@ -678,17 +677,22 @@ def mark(request, exam_pk, sk, unmarked_exam_answers_only=True, review=False):
incorrect_answers.remove("normal")
else:
if review:
unmarked_user_answers = question.get_user_answers(exam_pk=exam_pk, include_normal=False)
unmarked_user_answers = question.get_user_answers(
exam_pk=exam_pk, include_normal=False
)
elif unmarked_exam_answers_only:
unmarked_user_answers = question.get_unmarked_user_answers(exam_pk=exam_pk)
else:
unmarked_user_answers = question.get_unmarked_user_answers()
if not unmarked_exam_answers_only:
correct_answers = question.answers.filter(status=Answer.MarkOptions.CORRECT)
half_mark_answers = question.answers.filter(status=Answer.MarkOptions.HALF_MARK)
incorrect_answers = question.answers.filter(status=Answer.MarkOptions.INCORRECT)
half_mark_answers = question.answers.filter(
status=Answer.MarkOptions.HALF_MARK
)
incorrect_answers = question.answers.filter(
status=Answer.MarkOptions.INCORRECT
)
if review:
for ans in unmarked_user_answers:
@@ -706,7 +710,6 @@ def mark(request, exam_pk, sk, unmarked_exam_answers_only=True, review=False):
unmarked_answers_bool = True
review_user_answers.append((ans, mark))
return render(
request,
"rapids/mark.html",
@@ -780,17 +783,15 @@ def exam_scores_cid(request, pk):
by_question[q].append((ans, answer_score))
user_scores = {}
user_scores_normalised = {}
for user in user_answers_marks:
user_scores[user] = sum(
[i for i in user_answers_marks[user] if i != "unmarked"]
)
user_scores_normalised[user] = normaliseScore(sum(
[i for i in user_answers_marks[user] if i != "unmarked"]
))
user_scores_normalised[user] = normaliseScore(
sum([i for i in user_answers_marks[user] if i != "unmarked"])
)
user_scores_list = list(user_scores.values())
@@ -859,7 +860,6 @@ def exam_scores_cid_user(request, pk, cid):
answers_marks = []
answers = []
view_all_results = False
if request.user.groups.filter(name="view_all_results").exists():
view_all_results = True
@@ -1103,6 +1103,7 @@ def question_save_annotation(request, pk):
data = {"status": "error"}
return JsonResponse(data, status=400)
class ExamClone(ExamCloneMixin, ExamCreate):
"""Clone exam view"""
@@ -1115,8 +1116,47 @@ def get_question_by_hash(request):
try:
question = RapidImage.objects.get(image_md5_hash=hash)
data = {"status": "success", "id": question.pk, "url": question.rapid.get_absolute_url()}
data = {
"status": "success",
"id": question.pk,
"url": question.rapid.get_absolute_url(),
}
return JsonResponse(data, status=200)
except RapidImage.DoesNotExist:
data = {"status": "success", "id": False}
return JsonResponse(data, status=200)
return JsonResponse(data, status=200)
# TODO: better permissions
@login_required
def question_json_unbased(request, pk):
"""
No (file based) caching is enabled for unbased quesitons
"""
question = get_object_or_404(Rapid, pk=pk)
question_json = question.get_question_json(based=False)
return JsonResponse(question_json)
@login_required
def question_json(request, pk):
question = get_object_or_404(Rapid, pk=pk)
question_json = question.get_question_json(based=True)
return JsonResponse(question_json)
@login_required
def question_viewer(request, pk):
#question = get_object_or_404(Rapid, pk=pk)
ids = request.GET.get("ids").split(",")
return render(
request,
"rapids/question_viewer.html",
{
"ids": ids,
},
)