updating management command to delete hanging logical file for additional logical file types
@@ -10,13 +10,25 @@ from hs_file_types.models.netcdf import NetCDFLogicalFile
from hs_file_types.models.raster import GeoRasterLogicalFile
from hs_file_types.models.reftimeseries import RefTimeseriesLogicalFile
from hs_file_types.models.timeseries import TimeSeriesLogicalFile
+from hs_file_types.models.model_instance import ModelInstanceLogicalFile
+from hs_file_types.models.model_program import ModelProgramLogicalFile
+from hs_file_types.models.fileset import FileSetLogicalFile
def delete_hanging_logical_files(logical_files):
count = 0
- for file in logical_files:
- if not file.files.all() or not hasattr(file, 'resource'):
- file.delete()
+ for lf in logical_files:
+ if not hasattr(lf, 'resource'):
+ lf.delete()
+ count = count + 1
+ elif not lf.files.all():
+ if lf.is_fileset:
+ # we allow fileset to not have any files
+ continue
+ elif lf.is_model_instance and lf.folder:
+ # we allow model instance based on folder to not have any files
+ continue
+ lf.delete()
count = count + 1
return count
@@ -37,3 +49,9 @@ class Command(BaseCommand):
print(">> {} RefTimeseriesLogicalFile deleted".format(count))
count = delete_hanging_logical_files(TimeSeriesLogicalFile.objects.all())
print(">> {} TimeSeriesLogicalFile deleted".format(count))
+ count = delete_hanging_logical_files(ModelInstanceLogicalFile.objects.all())
+ print(">> {} ModelInstanceLogicalFile deleted".format(count))
+ count = delete_hanging_logical_files(ModelProgramLogicalFile.objects.all())
+ print(">> {} ModelProgramLogicalFile deleted".format(count))
+ count = delete_hanging_logical_files(FileSetLogicalFile.objects.all())
+ print(">> {} FileSetLogicalFile deleted".format(count))
