Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GWELLS-2011/2013] FEATURE** New attachments UI #2035

Merged
merged 28 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
1e9f2ef
wip - rework attachments table
davidclaveau Oct 27, 2023
a3eb77c
add document label codes
davidclaveau Oct 27, 2023
d9af5ee
wip - refactor Documents component
davidclaveau Oct 28, 2023
4dfcf3a
automate file name in uploader
LocalNewsTV Oct 30, 2023
e4d62cf
networked docker containers
LocalNewsTV Oct 31, 2023
9a5f7c0
change local API target from backend -> localhost
LocalNewsTV Oct 31, 2023
2eea134
locked uploadable file types
LocalNewsTV Oct 31, 2023
bdf62f1
update bootstrap vue package
LocalNewsTV Oct 31, 2023
82862d6
Create object maps for Well labels
LocalNewsTV Oct 31, 2023
2738199
Added file_name logic and datepicker
LocalNewsTV Oct 31, 2023
54812e2
update table headers for updated bootstrap package
LocalNewsTV Nov 1, 2023
e979c9d
update table header objects
LocalNewsTV Nov 1, 2023
6ee7ba9
update API to clean up returned public objects
LocalNewsTV Nov 2, 2023
7a29b2a
add longform labels to table
LocalNewsTV Nov 2, 2023
164a32d
wip - fix to upload docs from edit well
davidclaveau Nov 2, 2023
c31edb6
Added table to edit docs, removed old ul's
LocalNewsTV Nov 2, 2023
368f6be
fix to doc upload, allow deletion from edit
davidclaveau Nov 3, 2023
12a1857
code cleanup, change header names for clarity, fix public list bug
LocalNewsTV Nov 3, 2023
3b33b57
bug fix, documented getLongFormLabel
LocalNewsTV Nov 3, 2023
9a4e724
Files uploaded now flagged correctly (private)
LocalNewsTV Nov 3, 2023
d47b16b
documentation added
LocalNewsTV Nov 6, 2023
be6ca77
Code cleanup
LocalNewsTV Nov 6, 2023
538342f
update ui snapshots for tests
LocalNewsTV Nov 6, 2023
4df9880
revert document label migration (using obj map instead)
davidclaveau Nov 6, 2023
de7909a
bug fix for uploading files
LocalNewsTV Nov 6, 2023
1ae6ffe
bug fix when rendering in 'submit report'
LocalNewsTV Nov 6, 2023
39abae9
fix upload doc in submit report before wtn issued
davidclaveau Nov 7, 2023
f904a31
fix unviewable files in submission preview
LocalNewsTV Nov 7, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion app/backend/gwells/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import sys
import os
import logging
import re
from datetime import timedelta
from django.urls import reverse
from urllib.parse import quote, unquote_plus
Expand Down Expand Up @@ -122,11 +123,33 @@ def create_url_list(self, objects, host, bucket_name, private=False):
'url': self.create_url(document, host, bucket_name, private),

# split on last occurrence of '/' and return last item (supports any or no prefixes)
'name': unquote_plus(document.object_name).rsplit('/', 1)[-1]
'name': unquote_plus(document.object_name).rsplit('/', 1)[-1],
"well_number": self.extract_well_number(document.object_name),
"date_of_action": self.extract_date_of_action(document.object_name),
"well_label": self.extract_well_label(document.object_name),
"document_status": private
}, objects)
)
return urls

def extract_well_number(self, object_name):
try:
return re.findall(r'\d+', unquote_plus(object_name).rsplit('/', 1)[-1].split("_")[0])[0]
except IndexError:
return "Unknown"

def extract_date_of_action(self, object_name):
try:
return int(unquote_plus(object_name).rsplit('/', 1)[-1].split("_")[2].split(".")[0].strip())
except IndexError:
return -1

def extract_well_label(self, object_name):
try:
return unquote_plus(object_name).rsplit('/', 1)[-1].split("_")[1]
except IndexError:
return ""

def get_bucket_folder(self, document_id, resource='well'):
"""Helper function to determine the folder for a given resource"""
if resource == 'well':
Expand Down
2 changes: 1 addition & 1 deletion app/backend/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ requests==2.21.0
minio==7.1.16
coverage>=4.4.2
django-filter>=2.0.0,<2.1
drf-yasg==1.20.0
drf-yasg==1.21.7
django-cors-headers==2.2.0
django-extensions==2.0.6
cryptography<=40.0.2
Expand Down
6 changes: 6 additions & 0 deletions app/backend/submissions/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,13 @@
WellPublicationStatusCode,
YieldEstimationMethodCode,
AquiferLithologyCode,
DocumentLabelCode
)
from submissions.models import WellActivityCode
from wells.serializers import (
CasingCodeSerializer,
CasingMaterialSerializer,
DocumentLabelCodeSerializer
)
from submissions.serializers import (
AlterationSubmissionDisplaySerializer,
Expand Down Expand Up @@ -486,6 +488,9 @@ def get(self, request, **kwargs):
instance=LithologyDescriptionCode.objects.all(), many=True)
licenced_status_codes = LicencedStatusCodeSerializer(
instance=LicencedStatusCode.objects.all(), many=True)

document_label_codes = DocumentLabelCodeSerializer(
instance=DocumentLabelCode.objects.all(), many=True)

root = urljoin('/', app_root, 'api/v2/')
for item in activity_codes.data:
Expand Down Expand Up @@ -536,6 +541,7 @@ def get(self, request, **kwargs):
options["well_publication_status_codes"] = well_publication_status_codes.data
options["observation_well_status"] = observation_well_status.data
options["licenced_status_codes"] = licenced_status_codes.data
options["document_label_codes"] = document_label_codes.data

return Response(options)

Expand Down
22 changes: 22 additions & 0 deletions app/backend/wells/data_migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,3 +377,25 @@ def update_update_user_fields(apps, schema_editor):
model.objects.filter(update_user__isnull=True).update(update_user=F('create_user'))
except AttributeError:
logger.error("skipping")

def document_label_codes():
"""
Generator that deserializes and provides document label codes.
"""
path = os.path.dirname(os.path.realpath(__file__))
with open(os.path.join(path, 'migrations/document_label_codes.json'), 'r') as json_data:
data = json.load(json_data)
for item in data:
yield item


def load_document_label_codes(apps, schema_editor):
DocumentLabelCode = apps.get_model('wells', 'DocumentLabelCode')
for item in document_label_codes():
DocumentLabelCode.objects.create(**item)


def unload_document_label_codes(apps, schema_editor):
DocumentLabelCode = apps.get_model('wells', 'DocumentLabelCode')
for item in document_label_codes():
DocumentLabelCode.objects.get(code=item.get('code')).delete()
41 changes: 41 additions & 0 deletions app/backend/wells/migrations/0142_add_document_label_codes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Generated by Django 2.2.28 on 2023-08-11 18:10

from django.db import migrations, models
import django.db.models.deletion
import datetime
from django.utils.timezone import utc
import gwells.db_comments.model_mixins
import wells.data_migrations


class Migration(migrations.Migration):

dependencies = [
('wells', '0141_add_drinking_water_protection_area_ind'),
]

operations = [
migrations.CreateModel(
name='DocumentLabelCode',
fields=[
('create_user', models.CharField(max_length=60)),
('create_date', models.DateTimeField(default=django.utils.timezone.now)),
('update_user', models.CharField(max_length=60)),
('update_date', models.DateTimeField(default=django.utils.timezone.now)),
('display_order', models.PositiveIntegerField()),
('effective_date', models.DateTimeField(default=django.utils.timezone.now)),
('expiry_date', models.DateTimeField(default=datetime.datetime(9999, 12, 31, 23, 59, 59, 999999, tzinfo=utc))),
('code', models.CharField(db_column='document_label_code', editable=False, max_length=10, primary_key=True, serialize=False)),
('description', models.CharField(max_length=100)),
],
options={
'db_table': 'document_label_code',
'ordering': ['display_order', 'description'],
},
bases=(models.Model, gwells.db_comments.model_mixins.DBComments),
),
migrations.RunPython(
code=wells.data_migrations.load_document_label_codes,
reverse_code=wells.data_migrations.unload_document_label_codes,
)
]
32 changes: 32 additions & 0 deletions app/backend/wells/migrations/document_label_codes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[
{
"code": "LABEL0",
"create_user": "WELLS",
"create_date": "2018-08-14T17:42:52.421Z",
"update_user": "WELLS",
"update_date": "2018-08-14T17:42:52.421Z",
"description": "Label 0",
"display_order": 0,
"effective_date": "2013-11-07T05:28:00.402Z"
},
{
"code": "LABEL1",
"create_user": "WELLS",
"create_date": "2018-08-14T17:42:52.423Z",
"update_user": "WELLS",
"update_date": "2018-08-14T17:42:52.423Z",
"description": "Label 1",
"display_order": 1,
"effective_date": "2018-08-14T17:42:52.423Z"
},
{
"code": "LABEL2",
"create_user": "WELLS",
"create_date": "2018-08-14T17:42:52.416Z",
"update_user": "WELLS",
"update_date": "2018-08-14T17:42:52.416Z",
"description": "Label 2",
"display_order": 2,
"effective_date": "2018-08-14T17:42:52.416Z"
}
]
17 changes: 17 additions & 0 deletions app/backend/wells/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2596,3 +2596,20 @@ def as_dict(self):
"analysis_method": self.analysis_method,
"comments": self.comments
}

class DocumentLabelCode(CodeTableModel):
"""
Type of labels for a document
"""
code = models.CharField(primary_key=True, max_length=10,
editable=False, db_column='document_label_code')
description = models.CharField(max_length=100)

class Meta:
db_table = 'document_label_code'
ordering = ['display_order', 'description']

db_table_comment = ('Describes the label of a document. E.g. Well Driller Report, Well Record')

def __str__(self):
return self.description
11 changes: 10 additions & 1 deletion app/backend/wells/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
LithologyDescription,
Screen,
Well,
AquiferParameters
AquiferParameters,
DocumentLabelCode
)
from submissions.models import WellActivityCode

Expand Down Expand Up @@ -1191,3 +1192,11 @@ class Meta:
"longitude",
"lithologydescription_set"
)

class DocumentLabelCodeSerializer(serializers.ModelSerializer):
class Meta:
model = DocumentLabelCode
fields = (
'code',
'description',
)
Loading