Skip to content

Commit

Permalink
Merge pull request #2381 from SEED-platform/fix-500-errors
Browse files Browse the repository at this point in the history
500 errors for /api/v2/properties/columns/
  • Loading branch information
adrian-lara committed Aug 31, 2020
2 parents 49afd47 + 7f04c2a commit d97ce5c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion seed/api/v2_1/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def _get_property_view(self, pk, cycle_pk):
Return a property view based on the property id and cycle
:param pk: ID of property (not property view)
:param cycle_pk: ID of the cycle
:return: dict, propety view and status
:return: dict, property view and status
"""
try:
property_view = PropertyView.objects.select_related(
Expand Down
24 changes: 19 additions & 5 deletions seed/views/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -815,13 +815,27 @@ def columns(self, request):
required: false
paramType: query
"""
organization_id = int(request.query_params.get('organization_id'))
org_id = request.query_params.get('organization_id', None)
if not org_id:
return JsonResponse(
{'status': 'error', 'message': 'Need to pass organization_id as query parameter'},
status=status.HTTP_400_BAD_REQUEST)
org_id = int(org_id)

try:
Organization.objects.get(pk=org_id)
except Organization.DoesNotExist:
return JsonResponse({
'status': 'error',
'message': 'organization with id %s does not exist' % org_id
}, status=status.HTTP_404_NOT_FOUND)

only_used = json.loads(request.query_params.get('only_used', 'false'))
columns = Column.retrieve_all(organization_id, 'property', only_used)
organization = Organization.objects.get(pk=organization_id)
unitted_columns = [add_pint_unit_suffix(organization, x) for x in columns]
columns = Column.retrieve_all(org_id, 'property', only_used)
organization = Organization.objects.get(pk=org_id)
columns_with_units = [add_pint_unit_suffix(organization, x) for x in columns]

return JsonResponse({'status': 'success', 'columns': unitted_columns})
return JsonResponse({'status': 'success', 'columns': columns_with_units})

@api_endpoint_class
@ajax_request_class
Expand Down

0 comments on commit d97ce5c

Please sign in to comment.