Skip to content

Commit

Permalink
code cleanup to fit python conventions
Browse files Browse the repository at this point in the history
  • Loading branch information
LocalNewsTV committed Nov 17, 2023
1 parent 5c44522 commit b7ea7d0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
1 change: 1 addition & 0 deletions app/backend/wells/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
url(api_path_prefix() + r'/wells/(?P<tag>[0-9]+)/files$',
never_cache(views.ListFiles.as_view()), name='file-list'),

# Increment/Decrement count of files for a given well during uploads
url(api_path_prefix() + r'/wells/(?P<tag>[0-9]+)/sum$',
never_cache(views.FileSumView.as_view()), name='file-sums'),

Expand Down
21 changes: 10 additions & 11 deletions app/backend/wells/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,27 +222,26 @@ def get(self, request, tag, **kwargs):
if not self.request.user.groups.filter(name=WELLS_EDIT_ROLE).exists():
return HttpResponse(status=403)
increment = self.request.query_params.get('inc')
documentType = self.request.query_params.get('documentType')
document_type = self.request.query_params.get('documentType')

# Verify we have correct query params, and the document type is valid
if self.request.query_params.get('documentType') == None \
or increment == None \
or not any(item['value'] == documentType for item in WELL_TAGS):
or not any(item['value'] == document_type for item in WELL_TAGS):
return HttpResponse(status=400)

attachment = documentType.replace(' ', "_").lower()
attachment = document_type.replace(' ', "_").lower()
try:
if increment == "true":
wellAttach = WellAttachment.objects.get(well_tag_number=tag)
setattr(wellAttach, attachment, getattr(wellAttach, attachment) + 1)
wellAttach.save()
well_attach = WellAttachment.objects.get(well_tag_number=tag)
setattr(well_attach, attachment, getattr(well_attach, attachment) + 1)
well_attach.save()
return HttpResponse("Count updated successfully", status=200)
elif increment == "false":
wellAttach = WellAttachment.objects.get(well_tag_number=tag)
currValue = getattr(wellAttach, attachment)
if currValue > 0:
setattr(wellAttach, attachment, getattr(wellAttach, attachment) - 1)
wellAttach.save()
well_attach = WellAttachment.objects.get(well_tag_number=tag)
if getattr(well_attach, attachment) > 0:
setattr(well_attach, attachment, getattr(well_attach, attachment) - 1)
well_attach.save()
return HttpResponse("File count decreased", status=200)
else:
return HttpResponse("Cannot have negative number of files", status=400)
Expand Down

0 comments on commit b7ea7d0

Please sign in to comment.