From 12b7fa6629e2f8a6d017b2178a331845f8aa55a5 Mon Sep 17 00:00:00 2001 From: Ross Date: Mon, 17 Nov 2025 10:34:27 +0000 Subject: [PATCH] Refactor CaseDetail references to Casedetail across templates and views - Updated all instances of 'case_detail' to 'casedetail' in templates to maintain consistency. - Adjusted view functions to use 'casedetail' instead of 'case_detail' for better clarity. - Renamed the field 'case_detail' to 'casedetail' in the CasePrior model to align with the new naming convention. - Ensured that all related logic and references in forms and data handling reflect this change. --- atlas/forms.py | 27 +- ...se_detail_caseprior_casedetail_and_more.py | 22 ++ atlas/models.py | 6 +- atlas/templates/atlas/case_display_block.html | 2 +- .../atlas/collection_case_details.html | 4 +- .../atlas/collection_case_displaysetup.html | 11 +- .../atlas/collection_case_priors.html | 6 +- .../atlas/collection_case_questions.html | 12 +- .../atlas/collection_case_view_take.html | 4 +- .../collection_case_view_take_answers.html | 6 +- .../atlas/collection_mark_overview.html | 4 +- .../atlas/collection_question_schemas.html | 10 +- atlas/templates/atlas/collection_viva.html | 30 +-- atlas/templates/atlas/normals_list.html | 2 +- .../templates/atlas/partials/_prior_card.html | 4 +- .../partials/collection_question_block.html | 10 +- .../atlas/partials/series_cases_list.html | 2 +- .../templates/atlas/question_link_header.html | 42 ++-- atlas/views.py | 234 ++++++++++-------- 19 files changed, 230 insertions(+), 208 deletions(-) create mode 100644 atlas/migrations/0085_rename_case_detail_caseprior_casedetail_and_more.py diff --git a/atlas/forms.py b/atlas/forms.py index 427c1e57..91a73cdd 100755 --- a/atlas/forms.py +++ b/atlas/forms.py @@ -831,7 +831,7 @@ class BaseReportAnswerForm(ModelForm): # "answer": "Write your answer in here." # } - def __init__(self, *args, case_detail, **kwargs): + def __init__(self, *args, casedetail, **kwargs): super(BaseReportAnswerForm, self).__init__(*args, **kwargs) self.fields["answer"].required = False @@ -847,12 +847,12 @@ class BaseQuestionAnswerForm(ModelForm): # "answer": "Write your answer in here." # } - def __init__(self, *args, case_detail, **kwargs): + def __init__(self, *args, casedetail, **kwargs): super(BaseQuestionAnswerForm, self).__init__(*args, **kwargs) - # self.fields["json_answer"].schema = case_detail.question_schema - if case_detail.question_schema is not None: + # self.fields["json_answer"].schema = casedetail.question_schema + if casedetail.question_schema is not None: self.fields["json_answer"] = JSONSchemaField( - schema=case_detail.question_schema, options="schema/options.json" + schema=casedetail.question_schema, options="schema/options.json" ) self.fields["json_answer"].label = "" @@ -1153,23 +1153,6 @@ class PriorCaseForm(Form): prior_visibility = CharField(max_length=2, required=True) - # def __init__(self, *args, **kwargs): - # self.case_detail = kwargs.pop( - # "case_detail" - # ) # To get request.user. Do not use kwargs.pop('user', None) due to potential security hole - - # super(PriorCaseForm, self).__init__(*args, **kwargs) - - # prior_cases = self.case_detail.case.get_all_prior_cases() - - # if not prior_cases: - # prior_cases = Case.objects.none() - - # self.fields["case"] = ChoiceField( - # required=False, - # # widget=Select(verbose_name="Series", is_stacked=False), - # ) - class CaseSeriesForm(forms.ModelForm): def __init__(self, *args, queryset, user=None, is_atlas_editor=False, **kwargs): diff --git a/atlas/migrations/0085_rename_case_detail_caseprior_casedetail_and_more.py b/atlas/migrations/0085_rename_case_detail_caseprior_casedetail_and_more.py new file mode 100644 index 00000000..7e9ab17d --- /dev/null +++ b/atlas/migrations/0085_rename_case_detail_caseprior_casedetail_and_more.py @@ -0,0 +1,22 @@ +# Generated by Django 5.2.7 on 2025-11-17 10:28 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('atlas', '0084_resource_open_access'), + ] + + operations = [ + migrations.RenameField( + model_name='caseprior', + old_name='case_detail', + new_name='casedetail', + ), + migrations.AlterUniqueTogether( + name='caseprior', + unique_together={('casedetail', 'prior_case')}, + ), + ] diff --git a/atlas/models.py b/atlas/models.py index 4026107f..fc734e9a 100644 --- a/atlas/models.py +++ b/atlas/models.py @@ -1545,7 +1545,7 @@ class CaseDetail(models.Model): return mark_safe(html) class CasePrior(models.Model): - case_detail = models.ForeignKey(CaseDetail, on_delete=models.CASCADE) + casedetail = models.ForeignKey(CaseDetail, on_delete=models.CASCADE) prior_case = models.ForeignKey(Case, on_delete=models.CASCADE, related_name="prior_case") relation_text = models.CharField(max_length=255, blank=True, help_text="Text to describe the relationship between the cases") @@ -1564,10 +1564,10 @@ class CasePrior(models.Model): ) class Meta: - unique_together = ("case_detail", "prior_case") + unique_together = ("casedetail", "prior_case") def __str__(self) -> str: - return f"{self.case_detail.case} -> {self.prior_case}" + return f"{self.casedetail.case} -> {self.prior_case}" class BaseReportAnswer(models.Model): question = models.ForeignKey(CaseDetail, on_delete=models.CASCADE) diff --git a/atlas/templates/atlas/case_display_block.html b/atlas/templates/atlas/case_display_block.html index a7515fc9..11943278 100755 --- a/atlas/templates/atlas/case_display_block.html +++ b/atlas/templates/atlas/case_display_block.html @@ -464,7 +464,7 @@ {% if casedetail %} - {% include 'atlas/partials/collection_question_block.html' with case_detail=casedetail can_edit=can_edit %} + {% include 'atlas/partials/collection_question_block.html' with can_edit=can_edit %} {% endif %} diff --git a/atlas/templates/atlas/collection_case_details.html b/atlas/templates/atlas/collection_case_details.html index d284bb08..8e7789c9 100644 --- a/atlas/templates/atlas/collection_case_details.html +++ b/atlas/templates/atlas/collection_case_details.html @@ -3,9 +3,9 @@ {% block content %} - {% include 'atlas/partials/_viewing_case_as_part_of_collection.html' %} + {% include 'atlas/partials/_viewing_case_as_part_of_collection.html' with nav_link_view="atlas:collection_case_details" %} -

Case: {{case_detail.case.title}}

+

Case: {{casedetail.case.title}}

This page allows you to configure how the case is displayed as part of the collection.

diff --git a/atlas/templates/atlas/collection_case_displaysetup.html b/atlas/templates/atlas/collection_case_displaysetup.html index 9112f87c..88871f51 100644 --- a/atlas/templates/atlas/collection_case_displaysetup.html +++ b/atlas/templates/atlas/collection_case_displaysetup.html @@ -3,13 +3,14 @@ {% block content %} +{% include 'atlas/partials/_viewing_case_as_part_of_collection.html' with nav_link_view="atlas:collection_case_displaysetup" %}

Setup default display for case

-
@@ -29,7 +30,7 @@ document.getElementById('save-viewerstate').addEventListener('click', function() document.getElementById('viewerstate-save-response').innerHTML = "Viewer state could not be retrieved."; return; } - fetch("{% url 'atlas:collection_case_displaysetup' case_detail.collection.pk case_detail.case.pk %}", { + fetch("{% url 'atlas:collection_case_displaysetup' casedetail.collection.pk casedetail.case.pk %}", { method: "POST", headers: { "Content-Type": "application/json", @@ -46,7 +47,7 @@ document.getElementById('save-viewerstate').addEventListener('click', function() }); }); document.getElementById('reset-viewerstate').addEventListener('click', function() { - fetch("{% url 'atlas:collection_case_displaysetup' case_detail.collection.pk case_detail.case.pk %}", { + fetch("{% url 'atlas:collection_case_displaysetup' casedetail.collection.pk casedetail.case.pk %}", { method: "POST", headers: { "Content-Type": "application/json", diff --git a/atlas/templates/atlas/collection_case_priors.html b/atlas/templates/atlas/collection_case_priors.html index bf80c144..4cd5db6b 100644 --- a/atlas/templates/atlas/collection_case_priors.html +++ b/atlas/templates/atlas/collection_case_priors.html @@ -4,9 +4,9 @@ {% block content %} - {% include 'atlas/partials/_viewing_case_as_part_of_collection.html' with casedetail=case_detail %} + {% include 'atlas/partials/_viewing_case_as_part_of_collection.html' with nav_link_view="atlas:collection_case_priors" %} -

Case: {{case_detail.case.title}}

+

Managing Priors for Case: {{casedetail.case.title}}

@@ -19,7 +19,7 @@
{% for case, added, relation, visibility in available_priors %} - {% include 'atlas/partials/_prior_card.html' with case=case added=added relation=relation visibility=visibility case_detail=case_detail collection=collection %} + {% include 'atlas/partials/_prior_card.html' with case=case added=added relation=relation visibility=visibility collection=collection %} {% empty %}
No available prior cases found for the case.
diff --git a/atlas/templates/atlas/collection_case_questions.html b/atlas/templates/atlas/collection_case_questions.html index 26fdb5ba..89006043 100644 --- a/atlas/templates/atlas/collection_case_questions.html +++ b/atlas/templates/atlas/collection_case_questions.html @@ -4,11 +4,11 @@ {% block content %} - {% include 'atlas/partials/_viewing_case_as_part_of_collection.html' with casedetail=case_detail %} + {% include 'atlas/partials/_viewing_case_as_part_of_collection.html' with nav_link_view="atlas:collection_case_questions" %} -

Case: {{case_detail.case.title}}

+

Case: {{casedetail.case.title}}

- {% if case_detail.question_schema is not None and not case_detail.question_answers %} + {% if casedetail.question_schema is not None and not casedetail.question_answers %} {# Hidden per-case question snippet to inject when case is loaded #} {% if case.display_sets.all %}
Display Sets: @@ -212,14 +212,14 @@ let c = this.closest(".case-item"); console.log('clicked local', c) console.log('open local', c.dataset.case) - case_details = JSON.parse(c.dataset.casejson); + casedetails = JSON.parse(c.dataset.casejson); let viewerstate = JSON.parse(c.dataset.viewerstate) || {}; $('#loading-case').show() $("#open-viewer-local").addClass("flash-button"); $('#current-case-title').html("Case: "+c.dataset.title); - $("#current-case-history").html("History: "+case_details['history']); - $("#current-case-discussion").html("Discussion: "+case_details['discussion']); - $("#current-case-report").html("Report: "+case_details['report']); + $("#current-case-history").html("History: "+casedetails['history']); + $("#current-case-discussion").html("Discussion: "+casedetails['discussion']); + $("#current-case-report").html("Report: "+casedetails['report']); bc.postMessage({"type": "open", "case" : c.dataset.case, "images": c.dataset.images, @@ -239,15 +239,15 @@ let c = this; console.log('clicked local', c) console.log('open local', c.dataset.case) - case_details = JSON.parse(c.dataset.casejson); + casedetails = JSON.parse(c.dataset.casejson); let viewerstate = JSON.parse(c.dataset.viewerstate) || {}; let annotations = JSON.parse(c.dataset.annotations) || {}; $('#loading-case').show() $("#open-viewer-local").addClass("flash-button"); $('#current-case-title').html("Case: "+c.dataset.title); - $("#current-case-history").html("History: "+case_details['history']); - $("#current-case-discussion").html("Discussion: "+case_details['discussion']); - $("#current-case-report").html("Report: "+case_details['report']); + $("#current-case-history").html("History: "+casedetails['history']); + $("#current-case-discussion").html("Discussion: "+casedetails['discussion']); + $("#current-case-report").html("Report: "+casedetails['report']); bc.postMessage({"type": "open", "case" : c.dataset.case, "images": c.dataset.images, @@ -302,15 +302,15 @@ let c = $(this).closest(".case-item"); - case_details = c.data('casejson'); - console.log(case_details); + casedetails = c.data('casejson'); + console.log(casedetails); $('#loading-case').show() $("#open-viewer").addClass("flash-button"); $('#current-case-title').html("Case: "+c.data('title')); - $("#current-case-history").html("History: "+case_details['history']); - $("#current-case-discussion").html("Discussion: "+case_details['discussion']); - $("#current-case-report").html("Report: "+case_details['report']); + $("#current-case-history").html("History: "+casedetails['history']); + $("#current-case-discussion").html("Discussion: "+casedetails['discussion']); + $("#current-case-report").html("Report: "+casedetails['report']); console.log($(this).data('type')) if ($(this).data('type') == 'case') { diff --git a/atlas/templates/atlas/normals_list.html b/atlas/templates/atlas/normals_list.html index 37b6eb51..a7d1c0df 100644 --- a/atlas/templates/atlas/normals_list.html +++ b/atlas/templates/atlas/normals_list.html @@ -26,7 +26,7 @@ {% if page_obj.object_list %} {% else %} -
{% csrf_token %} diff --git a/atlas/templates/atlas/partials/collection_question_block.html b/atlas/templates/atlas/partials/collection_question_block.html index e606a1cf..d635cdcc 100644 --- a/atlas/templates/atlas/partials/collection_question_block.html +++ b/atlas/templates/atlas/partials/collection_question_block.html @@ -1,10 +1,10 @@ {# Partial: render questions and answers as HTML. #} -{% if case_detail.question_schema %} +{% if casedetail.question_schema %}

Questions

- {% for name, prop in case_detail.question_schema.properties.items %} + {% for name, prop in casedetail.question_schema.properties.items %}
{{ prop.title|default:name }}
{% if prop.description %} @@ -18,8 +18,8 @@ {% endif %} {# Safely fetch the stored/example answer using the project's `get_item` filter. #} - {% if case_detail.question_answers %} - {% with correct=case_detail.question_answers|get_item:name %} + {% if casedetail.question_answers %} + {% with correct=casedetail.question_answers|get_item:name %}
Example / Correct: {% if correct %} @@ -37,7 +37,7 @@ {% if user_answer %} {% if user_answer|get_item:name %} {% with ua=user_answer|get_item:name %} - {% with correct=case_detail.question_answers|get_item:name %} + {% with correct=casedetail.question_answers|get_item:name %}
Your answer: {{ ua }} diff --git a/atlas/templates/atlas/partials/series_cases_list.html b/atlas/templates/atlas/partials/series_cases_list.html index 79689504..86825e98 100644 --- a/atlas/templates/atlas/partials/series_cases_list.html +++ b/atlas/templates/atlas/partials/series_cases_list.html @@ -2,7 +2,7 @@
    {% for case in series.case.all %}