better logic for view functions
@@ -216,6 +216,11 @@ def delete_aggregation(request, resource_id, hs_file_type, file_type_id, **kwarg
"""
response_data = {'status': 'error'}
+ if hs_file_type not in FILE_TYPE_MAP:
+ err_msg = "Unsupported aggregation type. Supported aggregation types are: {}"
+ err_msg = err_msg.format(FILE_TYPE_MAP.keys())
+ response_data['message'] = err_msg
+ return JsonResponse(response_data, status=status.HTTP_400_BAD_REQUEST)
res, _, _ = authorize(request, resource_id, needed_permission=ACTION_TO_AUTHORIZE.EDIT_RESOURCE)
if res.resource_type != "CompositeResource":
@@ -223,12 +228,6 @@ def delete_aggregation(request, resource_id, hs_file_type, file_type_id, **kwarg
response_data['message'] = err_msg
return JsonResponse(response_data, status=status.HTTP_400_BAD_REQUEST)
- if hs_file_type not in FILE_TYPE_MAP:
- err_msg = "Unsupported aggregation type. Supported aggregation types are: {}"
- err_msg = err_msg.format(FILE_TYPE_MAP.keys())
- response_data['message'] = err_msg
- return JsonResponse(response_data, status=status.HTTP_400_BAD_REQUEST)
-
content_type = ContentType.objects.get(app_label="hs_file_types", model=hs_file_type.lower())
logical_file_type_class = content_type.model_class()
aggregation = logical_file_type_class.objects.filter(id=file_type_id).first()
@@ -253,6 +252,11 @@ def move_aggregation(request, resource_id, hs_file_type, file_type_id, tgt_path=
"""moves all files associated with an aggregation and all the associated metadata.
"""
response_data = {'status': 'error'}
+ if hs_file_type not in FILE_TYPE_MAP:
+ err_msg = "Unsupported aggregation type. Supported aggregation types are: {}"
+ err_msg = err_msg.format(FILE_TYPE_MAP.keys())
+ response_data['message'] = err_msg
+ return JsonResponse(response_data, status=status.HTTP_400_BAD_REQUEST)
res, _, user = authorize(request, resource_id,
needed_permission=ACTION_TO_AUTHORIZE.EDIT_RESOURCE)
@@ -261,12 +265,6 @@ def move_aggregation(request, resource_id, hs_file_type, file_type_id, tgt_path=
response_data['message'] = err_msg
return JsonResponse(response_data, status=status.HTTP_400_BAD_REQUEST)
- if hs_file_type not in FILE_TYPE_MAP:
- err_msg = "Unsupported aggregation type. Supported aggregation types are: {}"
- err_msg = err_msg.format(FILE_TYPE_MAP.keys())
- response_data['message'] = err_msg
- return JsonResponse(response_data, status=status.HTTP_400_BAD_REQUEST)
-
content_type = ContentType.objects.get(app_label="hs_file_types", model=hs_file_type.lower())
logical_file_type_class = content_type.model_class()
aggregation = logical_file_type_class.objects.filter(id=file_type_id).first()
