Skip to content

Commit

Permalink
Merge pull request #491 from UoA-eResearch/GenerateDatasetDirectoryName
Browse files Browse the repository at this point in the history
Add programmatic creation of dataset directories if not handed off
  • Loading branch information
ChrisKSeal authored Jun 6, 2024
2 parents d1d8b15 + 5cfb142 commit e3e92ab
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
16 changes: 10 additions & 6 deletions tardis/tardis_portal/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1050,9 +1050,9 @@ def dehydrate(self, bundle):
if bundle.data["identifiers"] == []:
bundle.data.pop("identifiers")
if "tardis.apps.dataclassification" in settings.INSTALLED_APPS:
bundle.data[
"classification"
] = bundle.obj.data_classification.classification
bundle.data["classification"] = (
bundle.obj.data_classification.classification
)

if settings.ONLY_EXPERIMENT_ACLS:
dataset_count = exp.datasets.all().count()
Expand Down Expand Up @@ -1361,9 +1361,9 @@ def dehydrate(self, bundle):
if bundle.data["identifiers"] == []:
bundle.data.pop("identifiers")
if "tardis.apps.dataclassification" in settings.INSTALLED_APPS:
bundle.data[
"classification"
] = bundle.obj.data_classification.classification
bundle.data["classification"] = (
bundle.obj.data_classification.classification
)
return bundle

def prepend_urls(self):
Expand Down Expand Up @@ -1651,6 +1651,10 @@ def obj_create(self, bundle, **kwargs): # pylint: disable=R1702
classification = bundle.data.pop("classification")
bundle = super().obj_create(bundle, **kwargs)
dataset = bundle.obj
if not dataset.directory:
# Create a dataset directory
dataset.directory = f"ds-{dataset.id}/data/"
dataset.save()
# After the obj has been created
if (
"tardis.apps.identifiers" in settings.INSTALLED_APPS
Expand Down
15 changes: 15 additions & 0 deletions tardis/tardis_portal/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,4 +315,19 @@ def get_param_names(schema, metadata):
dfp.save()
else:
dfp.string_value = metadata[pname.name]

dfp.save()


@tardis_app.task(name="tardis_portal.dataset.build_directory", ignore_result=True)
def dataset_build_directory():
from tardis.tardis_portal.models.dataset import Dataset

datasets = Dataset.objects.filter(directory__isnull=True)
logger.info("Processing datasets for directories")
logger.info(f"Found: {datasets}")
for dataset in datasets:
primary_key = dataset.pk
logger.info(f"Processing dataset: {primary_key}")
dataset.directory = f"ds-{primary_key}/data/"
dataset.save()

0 comments on commit e3e92ab

Please sign in to comment.