From 80d2de9da5d94f55694e1baa07ce11a6c486087f Mon Sep 17 00:00:00 2001 From: Xinlyu Wang Date: Thu, 5 Dec 2024 15:40:42 +0800 Subject: [PATCH 01/11] Fix tag info bugs in observation management page --- wamtram2/static/js/observation_management.js | 14 ++++++++- .../wamtram2/observation_management.html | 4 +++ wamtram2/views.py | 29 ++++++++++--------- 3 files changed, 32 insertions(+), 15 deletions(-) diff --git a/wamtram2/static/js/observation_management.js b/wamtram2/static/js/observation_management.js index fc72237a..b72e6e34 100644 --- a/wamtram2/static/js/observation_management.js +++ b/wamtram2/static/js/observation_management.js @@ -276,6 +276,12 @@ function setTagInfo() { const tagContainer = document.getElementById('tagContainer'); if (tagContainer && initialData.tag_info?.recorded_tags) { tagContainer.innerHTML = ''; + + if (initialData.tag_info.recorded_tags.length === 0) { + tagContainer.innerHTML = '

No flipper tags found

'; + return; + } + initialData.tag_info.recorded_tags.forEach(tag => { const tagHtml = `
@@ -331,6 +337,12 @@ function setTagInfo() { const pitTagContainer = document.getElementById('pitTagContainer'); if (pitTagContainer && initialData.tag_info?.recorded_pit_tags) { pitTagContainer.innerHTML = ''; + + if (initialData.tag_info.recorded_pit_tags.length === 0) { + pitTagContainer.innerHTML = '

No PIT tags found

'; + return; + } + initialData.tag_info.recorded_pit_tags.forEach(pitTag => { const pitTagHtml = `
@@ -344,7 +356,7 @@ function setTagInfo() {
- +
@@ -103,69 +107,93 @@
Create for a Tagged Turtle
- {% if turtle %} -
-
-
Tag ID: {{ tag_id }}
-
- ID: +
+
+
Tag ID: {{ tag_id }}
+ +
Sex: {{ turtle.sex }}
+
Species: {{ turtle.species_code }}
+ {% if first_observation_date %} +
First Observed: {{ first_observation_date|perth_time|date:"Y-m-d" }}
+ {% endif %} + {% if latest_site %} +
Latest Site: {{ latest_site }}
+ {% endif %} +
+
+
+

Does the species and sex match the data sheet?

+ Yes, create a record for this turtle +
+ {% csrf_token %} + + + + + + + + {% comment %} {% endcomment %} + + No, create the record and review later + +
+
+ {% if turtle and existing_turtle_entry %} +
+

You are searching for a new tag given to an existing turtle this season. Here is the turtle information:

+
+
+
+
Tag ID: {{ tag_id }}
+ +
Sex: {{ turtle.sex }}
+
Species: {{ turtle.species_code }}
+
Tag Added Date: {{ existing_turtle_entry.entry_batch.entry_date|date:"Y-m-d" }}
+
Location: {{ existing_turtle_entry.place_code.place_name }}
-
Sex: {{ turtle.sex }}
-
Species: {{ turtle.species_code }}
- {% if first_observation_date %} -
First Observed: {{ first_observation_date|perth_time|date:"Y-m-d" }}
- {% endif %} - {% if latest_site %} -
Latest Site: {{ latest_site }}
- {% endif %}
-
-
-

Does the species and sex match the data sheet?

- Yes, create a record for this turtle -
- {% csrf_token %} - - - - - - - - {% comment %} {% endcomment %} + + {% endif %} + {% elif new_tag_entry %} +
+

No existing turtle found with this tag in the database, but an entry with this tag was found within this season:

+
+
+
+
Tag ID: {{ tag_id }}
+
Entry ID: {{ new_tag_entry.data_entry_id }}
+
Observation Date: {{ new_tag_entry.entry_batch.entry_date|date:"Y-m-d" }}
+
Place: {{ new_tag_entry.place_code.place_name }}
+
Species: {{ new_tag_entry.species_code.common_name }}
+
Sex: {{ new_tag_entry.sex }}
+
+
+
+

This may be a recapture of a new turtle from this season

+ Yes, Create New Data Entry + No, create the record and review later - -
- {% elif new_tag_entry %} -
-

No existing turtle found with this tag in the database, but an entry with this tag was found within this season:

-
-
-
-
Tag ID: {{ tag_id }}
-
Entry ID: {{ new_tag_entry.data_entry_id }}
-
Observation Date: {{ new_tag_entry.entry_batch.entry_date|date:"Y-m-d" }}
-
Place: {{ new_tag_entry.place_code.place_name }}
-
Species: {{ new_tag_entry.species_code.common_name }}
-
Sex: {{ new_tag_entry.sex }}
-
-
-

This may be a recapture of a new turtle from this season

- Yes, Create New Data Entry - - No, create the record and review later - -
{% endif %}
diff --git a/wamtram2/templates/wamtram2/trtentrybatch_detail.html b/wamtram2/templates/wamtram2/trtentrybatch_detail.html index dfe1e6c0..8d2ac68f 100644 --- a/wamtram2/templates/wamtram2/trtentrybatch_detail.html +++ b/wamtram2/templates/wamtram2/trtentrybatch_detail.html @@ -143,10 +143,10 @@
{% if request.user.is_superuser or request.user|has_group:"WAMTRAM2_STAFF" or request.user|has_group:"WAMTRAM2_TEAM_LEADER"%} - Validate this Batch + Validate this Batch {% endif %} {% if request.user.is_superuser %} - Add this batch to the database + Add this batch to the database {% endif %}
diff --git a/wamtram2/views.py b/wamtram2/views.py index b0d15c01..7d003c76 100644 --- a/wamtram2/views.py +++ b/wamtram2/views.py @@ -705,6 +705,7 @@ def get_success_url(self): batch_id = self.kwargs['batch_id'] return reverse_lazy('wamtram2:entry_batch_detail', kwargs={'batch_id': batch_id}) + class ProcessDataEntryBatchView(LoginRequiredMixin, View): """ View class for processing a data entry batch. @@ -759,6 +760,7 @@ def get(self, request, *args, **kwargs): else: return redirect("wamtram2:entry_batch_detail", batch_id=self.kwargs["batch_id"]) + class FindTurtleView(LoginRequiredMixin, View): """ View class for finding a turtle based on tag and pit tag ID. @@ -812,7 +814,6 @@ def get(self, request, *args, **kwargs): Q(new_pittag_id_3__pittag_id=tag_id) | Q(new_pittag_id_4__pittag_id=tag_id), observation_id__isnull=True, - turtle_id__isnull=True ).select_related('entry_batch', 'place_code', 'species_code').order_by('-entry_batch__entry_date').first() if batch_id: @@ -915,7 +916,7 @@ def post(self, request, *args, **kwargs): tag_type = "unknown_tag" if not turtle: - new_tag_entry = TrtDataEntry.objects.filter( + existing_turtle_entry = TrtDataEntry.objects.filter( Q(new_left_tag_id__tag_id=tag_id) | Q(new_left_tag_id_2__tag_id=tag_id) | Q(new_right_tag_id__tag_id=tag_id) | @@ -924,32 +925,86 @@ def post(self, request, *args, **kwargs): Q(new_pittag_id_2__pittag_id=tag_id) | Q(new_pittag_id_3__pittag_id=tag_id) | Q(new_pittag_id_4__pittag_id=tag_id), - observation_id__isnull=True, + turtle_id__isnull=False, + observation_id__isnull=True + ).select_related( + 'turtle_id', + 'entry_batch', + 'place_code', + 'species_code' ).order_by('-entry_batch__entry_date').first() - - if new_tag_entry: - if any([str(new_tag_entry.new_left_tag_id).upper() == str(tag_id).upper(), - str(new_tag_entry.new_left_tag_id_2).upper() == str(tag_id).upper()]): + + if existing_turtle_entry: + turtle = existing_turtle_entry.turtle_id + if any([ + str(existing_turtle_entry.new_left_tag_id).upper() == str(tag_id).upper(), + str(existing_turtle_entry.new_left_tag_id_2).upper() == str(tag_id).upper() + ]): tag_type = "recapture_tag" tag_side = "L" - elif any([str(new_tag_entry.new_right_tag_id).upper() == str(tag_id).upper(), - str(new_tag_entry.new_right_tag_id_2).upper() == str(tag_id).upper()]): + elif any([ + str(existing_turtle_entry.new_right_tag_id).upper() == str(tag_id).upper(), + str(existing_turtle_entry.new_right_tag_id_2).upper() == str(tag_id).upper() + ]): tag_type = "recapture_tag" tag_side = "R" else: tag_type = "recapture_pit_tag" tag_side = None else: - no_turtle_found = True + new_tag_entry = TrtDataEntry.objects.filter( + Q(new_left_tag_id__tag_id=tag_id) | + Q(new_left_tag_id_2__tag_id=tag_id) | + Q(new_right_tag_id__tag_id=tag_id) | + Q(new_right_tag_id_2__tag_id=tag_id) | + Q(new_pittag_id__pittag_id=tag_id) | + Q(new_pittag_id_2__pittag_id=tag_id) | + Q(new_pittag_id_3__pittag_id=tag_id) | + Q(new_pittag_id_4__pittag_id=tag_id), + observation_id__isnull=True, + turtle_id__isnull=True + ).select_related( + 'entry_batch', + 'place_code', + 'species_code' + ).order_by('-entry_batch__entry_date').first() + + if new_tag_entry: + if any([ + str(new_tag_entry.new_left_tag_id).upper() == str(tag_id).upper(), + str(new_tag_entry.new_left_tag_id_2).upper() == str(tag_id).upper() + ]): + tag_type = "recapture_tag" + tag_side = "L" + elif any([ + str(new_tag_entry.new_right_tag_id).upper() == str(tag_id).upper(), + str(new_tag_entry.new_right_tag_id_2).upper() == str(tag_id).upper() + ]): + tag_type = "recapture_tag" + tag_side = "R" + else: + tag_type = "recapture_pit_tag" + tag_side = None + else: + no_turtle_found = True if turtle: - # if request.POST.get('create_and_review_later'): - # response = redirect(reverse('wamtram2:existingtrtdataentry', kwargs={'batch_id': batch_id, 'turtle_id': turtle.turtle_id})) - # response = self.set_cookie(response, batch_id, tag_id, tag_type, tag_side, do_not_process=True) - # return response - # else: - response = redirect(reverse('wamtram2:find_turtle', kwargs={'batch_id': batch_id})) + if existing_turtle_entry: + response = render(request, "wamtram2/find_turtle.html", { + "form": form, + "turtle": turtle, + "existing_turtle_entry": existing_turtle_entry, + "tag_id": tag_id, + "tag_type": tag_type, + "tag_side": tag_side, + "batch_id": batch_id, + "batch": batch, + "template_name": template_name, + }) + else: + response = redirect(reverse('wamtram2:find_turtle', kwargs={'batch_id': batch_id})) return self.set_cookie(response, batch_id, tag_id, tag_type, tag_side) + elif new_tag_entry: response = render(request, "wamtram2/find_turtle.html", { "form": form, @@ -3692,6 +3747,7 @@ def get_context_data(self, **kwargs): }) return context + def post(self, request, *args, **kwargs): if request.headers.get('X-Requested-With') == 'XMLHttpRequest': visible_columns = request.POST.getlist('columns[]') From 2ce6ae541d93648056c070d545f2e5f86c1d5575 Mon Sep 17 00:00:00 2001 From: Xinlyu Wang Date: Fri, 6 Dec 2024 13:58:03 +0800 Subject: [PATCH 03/11] Make super user can view all batches in move panel --- wamtram2/views.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/wamtram2/views.py b/wamtram2/views.py index 7d003c76..032fb95f 100644 --- a/wamtram2/views.py +++ b/wamtram2/views.py @@ -2637,7 +2637,14 @@ def handle_file_upload(self, request): class AvailableBatchesView(LoginRequiredMixin, View): def get(self, request): - user_orgs = request.user.organisations.all() + if request.user.is_superuser: + batches = TrtEntryBatches.objects.all() + else: + user_orgs = request.user.organisations.all() + batches = TrtEntryBatches.objects.filter( + batch_organisations__organisation__in=[org.code for org in user_orgs] + ) + current_batch_id = request.GET.get('current_batch_id') batches = TrtEntryBatches.objects.filter( From 9d4cddf1326f79f5d5cfe573bc1c8c9cbd5421e9 Mon Sep 17 00:00:00 2001 From: Xinlyu Wang Date: Fri, 6 Dec 2024 14:00:57 +0800 Subject: [PATCH 04/11] Add note for PIT tag in data entry form --- wamtram2/templates/wamtram2/trtdataentry_form.html | 3 +++ 1 file changed, 3 insertions(+) diff --git a/wamtram2/templates/wamtram2/trtdataentry_form.html b/wamtram2/templates/wamtram2/trtdataentry_form.html index 56b98856..6fa79e94 100644 --- a/wamtram2/templates/wamtram2/trtdataentry_form.html +++ b/wamtram2/templates/wamtram2/trtdataentry_form.html @@ -518,6 +518,9 @@
NEW Flipper Tag(s)
OLD PIT Tag(s)
+

+ Note: If you searched using a RIGHT PIT tag, please manually copy it to the right PIT tag field. +

From 143e4fe7ee4040f6f28202f57f550a4733eb340c Mon Sep 17 00:00:00 2001 From: Xinlyu Wang Date: Fri, 6 Dec 2024 14:02:17 +0800 Subject: [PATCH 05/11] Set existing_turtle_entry variable in find turtle --- wamtram2/views.py | 1 + 1 file changed, 1 insertion(+) diff --git a/wamtram2/views.py b/wamtram2/views.py index 032fb95f..bd5e82d0 100644 --- a/wamtram2/views.py +++ b/wamtram2/views.py @@ -892,6 +892,7 @@ def post(self, request, *args, **kwargs): new_tag_entry = None batch = None template_name = "No template associated" + existing_turtle_entry = None if batch_id: batch = TrtEntryBatches.objects.filter(entry_batch_id=batch_id).first() From 660a5ab936ea39263d0c9cfb15f2f7ffe40be6e3 Mon Sep 17 00:00:00 2001 From: Xinlyu Wang Date: Fri, 6 Dec 2024 14:03:12 +0800 Subject: [PATCH 06/11] Fix the display bug in find turtle page --- wamtram2/templates/wamtram2/find_turtle.html | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/wamtram2/templates/wamtram2/find_turtle.html b/wamtram2/templates/wamtram2/find_turtle.html index e7eb9954..d4a51edc 100644 --- a/wamtram2/templates/wamtram2/find_turtle.html +++ b/wamtram2/templates/wamtram2/find_turtle.html @@ -145,7 +145,7 @@
Create for a Tagged Turtle
- {% if turtle and existing_turtle_entry %} + {% elif existing_turtle_entry %}

You are searching for a new tag given to an existing turtle this season. Here is the turtle information:

@@ -169,7 +169,6 @@
Create for a Tagged Turtle
No, create new record
- {% endif %} {% elif new_tag_entry %}

No existing turtle found with this tag in the database, but an entry with this tag was found within this season:

From 7c55713a045ecdb67e79f64eeea355525880d031 Mon Sep 17 00:00:00 2001 From: Rick Wang Date: Fri, 6 Dec 2024 14:20:35 +0800 Subject: [PATCH 07/11] Fix the display bug in find turtle page --- wamtram2/templates/wamtram2/find_turtle.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wamtram2/templates/wamtram2/find_turtle.html b/wamtram2/templates/wamtram2/find_turtle.html index d4a51edc..bda06f3b 100644 --- a/wamtram2/templates/wamtram2/find_turtle.html +++ b/wamtram2/templates/wamtram2/find_turtle.html @@ -107,7 +107,7 @@
Create for a Tagged Turtle
- {% if turtle %} + {% if turtle and not existing_turtle_entry %}
Tag ID: {{ tag_id }}
From ddc73a28c173fc93dfbef6608757b6d5ad24af53 Mon Sep 17 00:00:00 2001 From: Xinlyu Wang Date: Fri, 6 Dec 2024 14:24:57 +0800 Subject: [PATCH 08/11] Fix move batch display bug --- wamtram2/views.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/wamtram2/views.py b/wamtram2/views.py index bd5e82d0..c6cd13af 100644 --- a/wamtram2/views.py +++ b/wamtram2/views.py @@ -2648,9 +2648,7 @@ def get(self, request): current_batch_id = request.GET.get('current_batch_id') - batches = TrtEntryBatches.objects.filter( - batch_organisations__organisation__in=[org.code for org in user_orgs] - ).exclude( + batches = batches.exclude( entry_batch_id=current_batch_id ).distinct() From 7bc1737ceebe2a2f363d799f88b9bd6053fa8054 Mon Sep 17 00:00:00 2001 From: Xinlyu Wang Date: Fri, 6 Dec 2024 14:29:46 +0800 Subject: [PATCH 09/11] Remove leave prompt after confirmed save --- wamtram2/templates/wamtram2/trtdataentry_form.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/wamtram2/templates/wamtram2/trtdataentry_form.html b/wamtram2/templates/wamtram2/trtdataentry_form.html index 6fa79e94..c2117ba0 100644 --- a/wamtram2/templates/wamtram2/trtdataentry_form.html +++ b/wamtram2/templates/wamtram2/trtdataentry_form.html @@ -1147,7 +1147,7 @@ // Prompt the user if they try to leave the page with unsaved changes window.addEventListener('beforeunload', function(event) { - if (isFormDirty) { + if (isFormDirty && !form.submitted) { event.preventDefault(); event.returnValue = ''; return ''; @@ -1157,6 +1157,7 @@ // Handle form submission form.addEventListener('submit', function(event) { if (form.checkValidity()) { + form.submitted = true; showLoadingOverlay(); isFormDirty = false; } else { From 1fc5c83a4dec441e8710c6c5e38b78b8d4fde7dc Mon Sep 17 00:00:00 2001 From: Xinlyu Wang Date: Fri, 6 Dec 2024 14:42:40 +0800 Subject: [PATCH 10/11] Remove leave prompt after confirmed save --- .../templates/wamtram2/trtdataentry_form.html | 46 ++++++++++++------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/wamtram2/templates/wamtram2/trtdataentry_form.html b/wamtram2/templates/wamtram2/trtdataentry_form.html index c2117ba0..877f1c8a 100644 --- a/wamtram2/templates/wamtram2/trtdataentry_form.html +++ b/wamtram2/templates/wamtram2/trtdataentry_form.html @@ -1142,12 +1142,14 @@ // Handle form changes to track dirty state form.addEventListener('input', function() { - isFormDirty = true; + if (!isSubmitting) { + isFormDirty = true; + } }); // Prompt the user if they try to leave the page with unsaved changes window.addEventListener('beforeunload', function(event) { - if (isFormDirty && !form.submitted) { + if (isFormDirty && !isSubmitting) { event.preventDefault(); event.returnValue = ''; return ''; @@ -1157,16 +1159,28 @@ // Handle form submission form.addEventListener('submit', function(event) { if (form.checkValidity()) { - form.submitted = true; - showLoadingOverlay(); - isFormDirty = false; + isSubmitting = true; + isFormDirty = false; + showLoadingOverlay(); + } else { - event.preventDefault(); - showLoadingOverlay(); - scrollToErrors(); + event.preventDefault(); + showLoadingOverlay(); + scrollToErrors(); } }); + + // Handle page reload on back navigation + window.addEventListener('pageshow', function(event) { + if (event.persisted) { + window.location.reload(); + isFormDirty = false; + isSubmitting = false; + } + }); + + function scrollToErrors() { const errorDiv = document.querySelector('.is-invalid'); if (errorDiv) { @@ -1182,13 +1196,6 @@ if (overlay) overlay.style.display = 'block'; if (spinner) spinner.style.display = 'block'; } - - // Handle page reload on back navigation - window.addEventListener('pageshow', function(event) { - if (event.persisted) { - window.location.reload(); - } - }); }); document.addEventListener('DOMContentLoaded', function() { const form = document.getElementById('dataEntryForm'); @@ -1220,6 +1227,8 @@ const confirmSaveButton = document.getElementById('confirmSaveButton'); const observationDateInput = document.querySelector('input[name="observation_date"]'); const dateErrorMessage = document.getElementById('date-error-message'); + let isFormDirty = false; + let isSubmitting = false; const labelMapping = { "search_entered_by": "Enterer", @@ -1382,9 +1391,12 @@ if (confirmSaveButton) { confirmSaveButton.addEventListener('click', function() { - $(summaryModal).modal('hide'); + isSubmitting = true; isFormDirty = false; - form.submit(); + $(summaryModal).modal('hide'); + setTimeout(() => { + form.submit(); + }, 100); }); } }); From 767ea3e8b6291d853158b799e844f86355b34ec2 Mon Sep 17 00:00:00 2001 From: Rick Wang Date: Fri, 6 Dec 2024 14:48:37 +0800 Subject: [PATCH 11/11] Update to 2.1.5 --- kustomize/overlays/prod/kustomization.yaml | 2 +- pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/kustomize/overlays/prod/kustomization.yaml b/kustomize/overlays/prod/kustomization.yaml index 9c513050..cc23cc08 100644 --- a/kustomize/overlays/prod/kustomization.yaml +++ b/kustomize/overlays/prod/kustomization.yaml @@ -23,5 +23,5 @@ patches: - path: service_patch.yaml images: - name: ghcr.io/dbca-wa/wastd - newTag: 2.1.0 + newTag: 2.1.5 diff --git a/pyproject.toml b/pyproject.toml index ba89af5c..2f287127 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "wastd" -version = "2.1.0" +version = "2.1.5" description = "Western Australian Sea Turtles Database" authors = ["Florian Mayer ", "Ashley Felton ","Evan Hallein ", "Rick Wang "]