From 9fc457c8a5bb705a6a6f9b520e00162f72e6fda7 Mon Sep 17 00:00:00 2001 From: Ross Date: Mon, 19 Dec 2022 10:24:51 +0000 Subject: [PATCH] Fixes for django 4 (remove is_ajax) --- Dockerfile | 3 ++- anatomy/views.py | 8 ++++---- atlas/views.py | 2 +- longs/views.py | 6 +++--- rad/views.py | 8 ++++---- rapids/views.py | 10 +++++----- requirements.txt | 8 +++++--- sbas/views.py | 2 -- 8 files changed, 24 insertions(+), 23 deletions(-) diff --git a/Dockerfile b/Dockerfile index a6bc18fa..2d971152 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,7 +13,8 @@ ENV PYTHONUNBUFFERED 1 # python3 python3-dev gcc \ # gfortran musl-dev \ # libffi-dev openssl-dev -RUN apt-get update && apt-get -y install postgresql postgresql-contrib +RUN apt-get update && apt-get -y install postgresql postgresql-contrib git + # install dependencies RUN pip install --upgrade pip diff --git a/anatomy/views.py b/anatomy/views.py index efe611ef..7f79b93f 100644 --- a/anatomy/views.py +++ b/anatomy/views.py @@ -634,7 +634,7 @@ def create_body_part(request): @csrf_exempt def get_body_part_id(request): - if request.is_ajax(): + if request.accepts("application/json")(): body_part_name = request.GET["body_part_name"] body_part_id = BodyPart.objects.get(name=body_part_name).id data = { @@ -660,7 +660,7 @@ def create_examination(request): @csrf_exempt def get_examination_id(request): - if request.is_ajax(): + if request.accepts("application/json")(): examination_name = request.GET["examination_name"] examination_id = Examination.objects.get(name=examination_name).id data = { @@ -686,7 +686,7 @@ def create_structure(request): @csrf_exempt def get_structure_id(request): - if request.is_ajax(): + if request.accepts("application/json")(): structure_name = request.GET["structure_name"] structure_id = Structure.objects.get(name=structure_name).id data = { @@ -718,7 +718,7 @@ class AnatomyQuestionView(LoginRequiredMixin, SingleTableMixin, FilterView): @user_is_author_or_anatomy_checker def question_save_annotation(request, pk): - if request.is_ajax() and request.method == "POST": + if request.method == "POST": question = get_object_or_404(AnatomyQuestion, pk=pk) question.image_annotations = request.POST.get("annotation") diff --git a/atlas/views.py b/atlas/views.py index 0b3210f0..6f28ff03 100755 --- a/atlas/views.py +++ b/atlas/views.py @@ -796,7 +796,7 @@ def atlas_scrap(request, pk): @csrf_exempt def get_examination_id(request): - if request.is_ajax(): + if request.accepts("application/json")(): examination_name = request.GET["examination_name"] examination_id = Examination.objects.get(name=examination_name).id data = { diff --git a/longs/views.py b/longs/views.py index fa0f1a76..845555c7 100755 --- a/longs/views.py +++ b/longs/views.py @@ -590,7 +590,7 @@ def create_examination(request): @csrf_exempt def get_examination_id(request): - if request.is_ajax(): + if request.accepts("application/json")(): examination_name = request.GET["examination_name"] examination_id = Examination.objects.get(name=examination_name).id data = { @@ -1210,7 +1210,7 @@ class UserAnswerDelete(SuperuserRequiredMixin, DeleteView): @user_passes_test(lambda u: u.is_superuser) def user_answer_delete_multiple(request): - if request.is_ajax(): + if request.accepts("application/json")(): answer_ids = json.loads(request.POST["answer_ids"]) # We could probably delete them all at once.... @@ -1244,7 +1244,7 @@ def question_review(request, pk): """ Return a json representation of the question when the exam is active """ - if request.is_ajax(): + if request.accepts("application/json")(): exam = get_object_or_404(Exam, pk=pk) if not exam.publish_results: diff --git a/rad/views.py b/rad/views.py index 439612f8..ef611254 100644 --- a/rad/views.py +++ b/rad/views.py @@ -281,7 +281,7 @@ def active_exams_unbased(request, cid=None, passcode=None): @csrf_exempt def exam_submit(request): print(request) - if request.is_ajax and request.method == "POST": + if request.method == "POST": print(request.POST) exam_type, exam_id = request.POST.get("eid").split("/") @@ -379,7 +379,7 @@ def feedback_mark_complete(request, pk): @csrf_exempt def answer_suggestion_submit(request): - if request.is_ajax and request.method == "POST": + if request.method == "POST": post_data = json.loads(request.body) question_type, qid = post_data["qid"].split("/") answer_string = post_data["answer"] @@ -411,7 +411,7 @@ def answer_suggestion_submit(request): @login_required def answer_submit(request): - if request.is_ajax and request.method == "POST": + if request.method == "POST": qid = request.POST.get("qid") question_type = request.POST.get("question_type") answer_string = request.POST.get("answer") @@ -442,7 +442,7 @@ def answer_submit(request): @login_required def answer_suggestion_confirm(request): - if request.is_ajax and request.method == "POST": + if request.method == "POST": question_type = request.POST.get("question_type") aid = request.POST.get("aid") status = request.POST.get("status") diff --git a/rapids/views.py b/rapids/views.py index d31e71d3..39bb5292 100755 --- a/rapids/views.py +++ b/rapids/views.py @@ -449,7 +449,7 @@ def create_abnormality(request): @csrf_exempt def get_abnormality_id(request): - if request.is_ajax(): + if request.accepts("application/json")(): abnormality_name = request.GET["abnormality_name"] abnormality_id = Abnormality.objects.get(name=abnormality_name).id data = { @@ -475,7 +475,7 @@ def create_examination(request): @csrf_exempt def get_examination_id(request): - if request.is_ajax(): + if request.accepts("application/json")(): examination_name = request.GET["examination_name"] examination_id = Examination.objects.get(name=examination_name).id data = { @@ -501,7 +501,7 @@ def create_region(request): @csrf_exempt def get_region_id(request): - if request.is_ajax(): + if request.accepts("application/json")(): region_name = request.GET["region_name"] region_id = Region.objects.get(name=region_name).id data = { @@ -849,7 +849,7 @@ def question_anonymise_dicom(request, pk): @user_is_author_or_rapid_checker def question_save_annotation(request, pk): - if request.is_ajax() and request.method == "POST": + if request.method == "POST": question = get_object_or_404(Rapid, pk=pk) image_annotations = json.loads(request.POST.get("annotation")) @@ -877,7 +877,7 @@ class ExamClone(ExamCloneMixin, ExamCreate): @login_required def get_question_by_hash(request): - if request.is_ajax() and request.method == "POST": + if request.method == "POST": hash = request.POST.get("hash") diff --git a/requirements.txt b/requirements.txt index 6470f6bd..bcb5bfe3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ -Django==3.2.13 +#Django==3.2.13 +Django==4.1.4 django_debug_toolbar django_jquery django_reversion @@ -16,7 +17,8 @@ pytesseract opencv-python pydicom django-dbbackup -django-hashedfilenamestorage +#django-hashedfilenamestorage +git+https://github.com/allysonbarros/django-hashedfilenamestorage#egg=django-hashedfilenamestorage djangorestframework django-tinymce django-zipview @@ -31,5 +33,5 @@ rich bs4 django-htmx debugpy -django-cookie-consent +git+https://github.com/jazzband/django-cookie-consent#django-cookie-consent django-crispy-forms \ No newline at end of file diff --git a/sbas/views.py b/sbas/views.py index 2f5d4d13..cb63bf1f 100644 --- a/sbas/views.py +++ b/sbas/views.py @@ -424,7 +424,6 @@ class UserAnswerDelete(SuperuserRequiredMixin, DeleteView): # @user_passes_test(lambda u: u.is_superuser) # def user_answer_delete_multiple(request): -# if request.is_ajax(): # print(request.POST["answer_ids"]) # answer_ids = json.loads(request.POST["answer_ids"]) # @@ -432,7 +431,6 @@ class UserAnswerDelete(SuperuserRequiredMixin, DeleteView): # for id in answer_ids: # CidUserAnswer.objects.get(pk=id).delete() # return JsonResponse({"status": "success"}) -# return JsonResponse({"status": "error"}) GenericViews = GenericViewBase("sbas", Question, CidUserAnswer, Exam)