Skip to content

Commit

Permalink
Merge pull request #2035 from bcgov/feature/documents-storage-overhaul-2
Browse files Browse the repository at this point in the history
[GWELLS-2011/2013] FEATURE** New attachments UI
  • Loading branch information
LocalNewsTV authored Nov 7, 2023
2 parents a7caea1 + f904a31 commit 50525e7
Show file tree
Hide file tree
Showing 22 changed files with 871 additions and 560 deletions.
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
2 changes: 1 addition & 1 deletion app/backend/submissions/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ def get(self, request, **kwargs):
instance=LithologyDescriptionCode.objects.all(), many=True)
licenced_status_codes = LicencedStatusCodeSerializer(
instance=LicencedStatusCode.objects.all(), many=True)

root = urljoin('/', app_root, 'api/v2/')
for item in activity_codes.data:
if item['code'] not in ('LEGACY'):
Expand Down
Loading

0 comments on commit 50525e7

Please sign in to comment.