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

[BUG][Gwells-2108] #2126

Merged
merged 3 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,4 @@ Code released under the [Apache License, Version 2.0](https://github.com/bcgov/g
More documentation for the repository can be found in the following places
- [Frontend](/app/frontend/README.md)
- [OpenShift](/openshift/README.md)
- [Tests](/tests/api-tests/README.md)
- [Tests](/tests/api-tests/README.md)
35 changes: 32 additions & 3 deletions app/backend/gwells/views/bulk.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
from django.db import transaction
from django.utils import timezone
from django.contrib.gis.geos import Point

from aquifers.constants import AQUIFER_ID_FOR_UNCORRELATED_WELLS
from aquifers.models import Aquifer, VerticalAquiferExtent, VerticalAquiferExtentsHistory
from wells.models import Well
from wells.models import Well, ActivitySubmission, FieldsProvided
from submissions.models import WellActivityCode
from gwells.models.bulk import BulkWellAquiferCorrelationHistory
from gwells.permissions import (
HasBulkWellAquiferCorrelationUploadRole,
Expand All @@ -45,6 +45,7 @@ class BulkWellAquiferCorrelation(APIView):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.change_log = []
self.change_log_activity_submission = []
self.create_date = timezone.now()
self.unknown_well_tag_numbers = set()
self.unknown_aquifer_ids = set()
Expand Down Expand Up @@ -109,13 +110,15 @@ def post(self, request, **kwargs):
'aquiferId': aquifer_id
}
wells_to_update.append(well)
self.append_to_change_log_activity_submission(well_tag_number, aquifer_id)
elif existing_aquifer_id != aquifer_id: # existing ids don't match - must be a change
self.append_to_change_log(well_tag_number, aquifer_id, existing_aquifer_id)
change = {
'action': 'update',
'existingAquiferId': existing_aquifer_id,
'newAquiferId': aquifer_id
}
self.append_to_change_log_activity_submission(well_tag_number, aquifer_id)
wells_to_update.append(well)

if change:
Expand Down Expand Up @@ -217,6 +220,16 @@ def update_wells(self, wells):
Well.objects.bulk_update(wells, ['aquifer'])
# save the BulkWellAquiferCorrelation records
BulkWellAquiferCorrelationHistory.objects.bulk_create(self.change_log)
# create a new row in activity submission table for each item in the array
for item in self.change_log_activity_submission:
activity_submission_object = ActivitySubmission.objects.create(create_user=item.create_user,
update_user=item.update_user,
create_date=item.create_date,
update_date=item.update_date,
well=item.well,
aquifer = item.aquifer,
well_activity_type=item.well_activity_type);
FieldsProvided.objects.create(activity_submission=activity_submission_object)

def append_to_change_log(self, well_tag_number, to_aquifer_id, from_aquifer_id):
bulk_history_item = BulkWellAquiferCorrelationHistory(
Expand All @@ -227,7 +240,23 @@ def append_to_change_log(self, well_tag_number, to_aquifer_id, from_aquifer_id):
create_date=self.create_date
)
self.change_log.append(bulk_history_item)


# add activity submission objects to the array
def append_to_change_log_activity_submission(self, well_tag_number, to_aquifer_id):
well_instance = Well.objects.get(pk=well_tag_number)
aquifer_instance = Aquifer.objects.get(pk=to_aquifer_id)
well_activity_code_instance = WellActivityCode.objects.get(pk=WellActivityCode.types.staff_edit().code)
activity_submission_item = ActivitySubmission(
create_user=self.request.user.profile.username,
update_user=self.request.user.profile.username,
create_date=self.create_date,
update_date=self.create_date,
well=well_instance,
aquifer = aquifer_instance,
well_activity_type=well_activity_code_instance
)
self.change_log_activity_submission.append(activity_submission_item)


class BulkVerticalAquiferExtents(APIView):
"""
Expand Down
Loading