From 57b9c712c2fe015605c02cf16a2b8fc698a3a532 Mon Sep 17 00:00:00 2001 From: Ross Date: Mon, 16 Feb 2026 10:28:32 +0000 Subject: [PATCH] Add delete functionality for image annotations in question detail view --- .../templates/anatomy/question_detail.html | 45 ++++++++++++++++--- anatomy/urls.py | 5 +++ anatomy/views.py | 11 +++++ 3 files changed, 54 insertions(+), 7 deletions(-) diff --git a/anatomy/templates/anatomy/question_detail.html b/anatomy/templates/anatomy/question_detail.html index a1aff538..44fa43c9 100644 --- a/anatomy/templates/anatomy/question_detail.html +++ b/anatomy/templates/anatomy/question_detail.html @@ -16,13 +16,21 @@
If important markers or arrows are not burned onto the image, please add annotations using the image annotation tool and click Save Annotations. Please note not all questions required image annotations in which case you can ignore this message.
{% endif %} -
-
- Image annotation help -
Annotate the image using the right mouse button to click and drag an arrow. To remove an arrow drag it out of the image boundaries. Click Save Annotations to persist. If required use the middle button to zoom and the left button to pan.
-
- - +
+
+
+ Image annotation help +
Annotate the image using the right mouse button to click and drag an arrow. To remove an arrow drag it out of the image boundaries. Click Save Annotations to persist. If required use the middle button to zoom and the left button to pan.
+
+
+
+
+ + {% if can_edit %} + + {% endif %} +
+
@@ -211,6 +219,29 @@ console.log('[Done]'); }) }) + $("#delete-annotations").click(function () { + if (!confirm('Clear saved annotations for this question? This cannot be undone.')) return; + $.ajax({ + url: "{% url 'anatomy:question_clear_annotation' pk=question.pk %}", + data: { + csrfmiddlewaretoken: "{{ csrf_token }}", + }, + type: "POST", + dataType: "json", + }) + .done(function (data) { + if (data.status == "success") { + toastr.info('Annotations cleared'); + // Optionally reload part of the page or remove the annotation overlay + location.reload(); + } else { + toastr.warning('Error clearing annotations'); + } + }) + .fail(function () { + toastr.warning('Error clearing annotations'); + }); + }); }); diff --git a/anatomy/urls.py b/anatomy/urls.py index 22cf7c1f..7607ff56 100644 --- a/anatomy/urls.py +++ b/anatomy/urls.py @@ -33,6 +33,11 @@ urlpatterns = [ views.question_save_annotation, name="question_save_annotation", ), + path( + "question//clear_annotation", + views.question_clear_annotation, + name="question_clear_annotation", + ), path( "question//suggest_incorrect_answers", views.question_suggest_incorrect_answers, diff --git a/anatomy/views.py b/anatomy/views.py index 3d7b60d8..436f6051 100644 --- a/anatomy/views.py +++ b/anatomy/views.py @@ -1504,6 +1504,17 @@ def question_save_annotation(request, pk): return JsonResponse(data, status=400) +@user_is_author_or_anatomy_checker +def question_clear_annotation(request, pk): + """Clear the stored image annotations for a question.""" + if request.method == "POST": + question = get_object_or_404(AnatomyQuestion, pk=pk) + question.image_annotations = "" + question.save(update_fields=["image_annotations"]) + return JsonResponse({"status": "success"}, status=200) + return JsonResponse({"status": "error"}, status=400) + + GenericExamViews = ExamViews( Exam, AnatomyQuestion, Answer, UserAnswer, "anatomy", "anatomy" )