Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
sanjaytkbabu committed Jan 31, 2024
1 parent abc3e3f commit 5550834
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 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 @@ -228,6 +241,23 @@ def append_to_change_log(self, well_tag_number, to_aquifer_id, from_aquifer_id):
)
self.change_log.append(bulk_history_item)

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)
# FieldsProvided.objects.create(filing_number=activity_submission_object.pk)



class BulkVerticalAquiferExtents(APIView):
"""
Expand Down

0 comments on commit 5550834

Please sign in to comment.