From 8973ac829f28d734ad14e5ae7ea7c16b5f7cad2d Mon Sep 17 00:00:00 2001
From: LocalNewsTV <62873746+LocalNewsTV@users.noreply.github.com>
Date: Mon, 4 Dec 2023 13:05:42 -0800
Subject: [PATCH 1/4] Create unmanaged WellLicence model
---
app/backend/wells/admin.py | 4 +++-
app/backend/wells/models.py | 10 ++++++++++
2 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/app/backend/wells/admin.py b/app/backend/wells/admin.py
index 751082e9d..403d2dc0a 100644
--- a/app/backend/wells/admin.py
+++ b/app/backend/wells/admin.py
@@ -20,7 +20,8 @@
FilterPackMaterialSizeCode,
FilterPackMaterialCode,
Well,
- WellAttachment
+ WellAttachment,
+ WellLicence
)
from gwells.models.lithology import (
LithologyColourCode, LithologyHardnessCode,
@@ -41,3 +42,4 @@
admin.site.register(FilterPackMaterialCode)
admin.site.register(Well)
admin.site.register(WellAttachment)
+admin.site.register(WellLicence)
diff --git a/app/backend/wells/models.py b/app/backend/wells/models.py
index 580668234..ee00e7e59 100644
--- a/app/backend/wells/models.py
+++ b/app/backend/wells/models.py
@@ -2640,3 +2640,13 @@ def __str__(self):
return_string += "{} File count: {}".format('Consultants Report',self.consultants_report)
return return_string
+
+class WellLicence(models.Model):
+ id = models.IntegerField(primary_key=True)
+ well_id = models.IntegerField()
+ waterrightslicence_id = models.IntegerField()
+ class Meta:
+ db_table = "well_licences"
+ managed = False
+ def __str__(self):
+ return "Well Number: " + str(self.well_id) + ", License #: " + str(self.waterrightslicence_id)
From 261e05e60b410c30e9e1486df6e185e95907b18b Mon Sep 17 00:00:00 2001
From: LocalNewsTV <62873746+LocalNewsTV@users.noreply.github.com>
Date: Mon, 4 Dec 2023 13:15:50 -0800
Subject: [PATCH 2/4] refactor well_licensing, remove unused imports
---
app/backend/wells/views.py | 65 +++++++++------------
app/frontend/src/wells/views/WellDetail.vue | 6 +-
2 files changed, 31 insertions(+), 40 deletions(-)
diff --git a/app/backend/wells/views.py b/app/backend/wells/views.py
index e37f1a640..2916365dd 100644
--- a/app/backend/wells/views.py
+++ b/app/backend/wells/views.py
@@ -74,8 +74,8 @@
WellClassCode,
WellYieldUnitCode,
WellStatusCode,
- AquiferParameters,
)
+
from wells.change_history import get_well_history
from wells.renderers import WellListCSVRenderer, WellListExcelRenderer
from wells.serializers import (
@@ -783,42 +783,33 @@ def lithology_geojson(request, **kwargs):
@api_view(['GET'])
def well_licensing(request, **kwargs):
tag = request.GET.get('well_tag_number')
- e_licensing_url = get_env_variable('E_LICENSING_URL')
- api_success = False
-
- headers = {
- 'content_type': 'application/json',
- 'AuthUsername': get_env_variable('E_LICENSING_AUTH_USERNAME'),
- 'AuthPass': get_env_variable('E_LICENSING_AUTH_PASSWORD')
- }
-
- if e_licensing_url:
- try:
- response = requests.get(e_licensing_url + '{}'.format(tag), headers=headers)
- if response.ok:
- try:
- licence = response.json()[-1] # Use the latest licensing value, fails purposely if empty array
- licence_status = 'Licensed' if licence.get('authorization_status') == 'ACTIVE' else 'Unlicensed'
- data = {
- 'status': licence_status,
- 'number': licence.get('authorization_number'),
- 'date': licence.get('authorization_status_date')
- }
- api_success = True
- except:
- pass
- except:
- pass
-
- if not api_success:
- well = Well.objects.get(well_tag_number=tag)
- data = {
- 'status': well.licenced_status.description,
- 'number': '',
- 'date': ''
- }
-
- return HttpResponse(json.dumps(data), content_type="application/json")
+ try:
+ if tag and tag.isnumeric():
+ well = Well.objects.get(well_tag_number=tag)
+ raw_query = """
+ SELECT DISTINCT
+ aw.licence_number
+ FROM well_licences wl
+ LEFT JOIN aquifers_waterrightslicence aw
+ ON aw.wrl_sysid = wl.waterrightslicence_id
+ WHERE well_id = %s
+ """
+
+ with connection.cursor() as cursor:
+ cursor.execute(raw_query, [tag])
+ result = cursor.fetchall()
+ flattened_result = [value for row in result for value in row]
+ data = {
+ 'status': well.licenced_status.description,
+ 'number': flattened_result,
+ 'date': ''
+ }
+ return JsonResponse(data)
+ except Exception as e:
+ return HttpResponse(status=500)
+ return HttpResponse(status=400)
+
+
# Deprecated. Use WellSubsurface instead
diff --git a/app/frontend/src/wells/views/WellDetail.vue b/app/frontend/src/wells/views/WellDetail.vue
index 7cff53c9d..2727b20da 100644
--- a/app/frontend/src/wells/views/WellDetail.vue
+++ b/app/frontend/src/wells/views/WellDetail.vue
@@ -135,9 +135,9 @@ Licensed under the Apache License, Version 2.0 (the "License");
Licensed Status: {{ wellLicence.status }}
- Licence Number:
-
- {{ wellLicence.number }}
+ Licence Number{{ wellLicence.number.length > 1 ? "s" : "" }}:
+
+ {{ licence}}{{ index + 1 < wellLicence.number.length ? ", " : ""}}
From 70ca468bccdd025b8eb9614d3ab9d78a21ff4da8 Mon Sep 17 00:00:00 2001
From: LocalNewsTV <62873746+LocalNewsTV@users.noreply.github.com>
Date: Mon, 4 Dec 2023 13:18:03 -0800
Subject: [PATCH 3/4] update test snapshot
---
.../specs/wells/__snapshots__/WellDetail.spec.js.snap | 8 --------
1 file changed, 8 deletions(-)
diff --git a/app/frontend/tests/unit/specs/wells/__snapshots__/WellDetail.spec.js.snap b/app/frontend/tests/unit/specs/wells/__snapshots__/WellDetail.spec.js.snap
index 3745635f9..0bfba078b 100644
--- a/app/frontend/tests/unit/specs/wells/__snapshots__/WellDetail.spec.js.snap
+++ b/app/frontend/tests/unit/specs/wells/__snapshots__/WellDetail.spec.js.snap
@@ -505,14 +505,6 @@ exports[`WellDetail.vue should match snapshot 1`] = `
-
-
-
-
-
Date: Mon, 4 Dec 2023 13:24:33 -0800
Subject: [PATCH 4/4] remove unused variable
---
app/backend/wells/views.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/app/backend/wells/views.py b/app/backend/wells/views.py
index 2916365dd..5bad3b0ab 100644
--- a/app/backend/wells/views.py
+++ b/app/backend/wells/views.py
@@ -805,7 +805,7 @@ def well_licensing(request, **kwargs):
'date': ''
}
return JsonResponse(data)
- except Exception as e:
+ except Exception:
return HttpResponse(status=500)
return HttpResponse(status=400)