cleanup of validation logic for creating file type
@@ -894,6 +894,19 @@ class AbstractLogicalFile(models.Model):
res_file = get_resource_file_by_id(resource, file_id)
if res_file is None or not res_file.exists:
raise ValidationError("File not found.")
+
+ logical_file = None
+ if res_file.has_logical_file:
+ logical_file = res_file.logical_file
+
+ if logical_file is not None:
+ if not logical_file.is_fileset and not logical_file.is_model_instance:
+ msg = "Selected file {} is already part of an aggregation.".format(res_file.file_name)
+ raise ValidationError(msg)
+ elif cls.__name__ == 'ModelProgramLogicalFile':
+ if logical_file.is_model_instance:
+ msg = "Model program aggregation is not allowed within a model instance aggregation"
+ raise ValidationError(msg)
else:
# user selected a folder to set aggregation - check if the specified folder exists
storage = resource.get_irods_storage()
@@ -916,20 +929,6 @@ class AbstractLogicalFile(models.Model):
msg = msg.format("Model instance", path_to_check)
raise ValidationError(msg)
- if cls.__name__ not in ['FileSetLogicalFile', 'ModelProgramLogicalFile', 'ModelInstanceLogicalFile']:
- if res_file is not None and res_file.has_logical_file:
- if not res_file.logical_file.is_fileset and not res_file.logical_file.is_model_instance:
- msg = "Selected {} {} is already part of an aggregation."
- if not folder_path:
- msg = msg.format('file', res_file.file_name)
- else:
- msg = msg.format('folder', folder_path)
- raise ValidationError(msg)
- elif cls.__name__ == 'ModelProgramLogicalFile':
- if res_file is not None and res_file.has_logical_file:
- if res_file.logical_file.is_model_instance:
- msg = "Model program aggregation is not allowed within a model instance aggregation"
- raise ValidationError(msg)
return res_file, folder_path
@classmethod
