Skip to content

Commit

Permalink
Improve sharing data (#736)
Browse files Browse the repository at this point in the history
* saving model instance updated so it set dataset storage path; deleting dataset, version and variable updated, to check if there are other relations

* setting dataset storage path moved to the model instance, deleted from api view

* file description updated in the admin panel

* blank line added
  • Loading branch information
sheenaze authored Sep 8, 2023
1 parent 023bb30 commit 48dd38e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
4 changes: 0 additions & 4 deletions api/views/upload_user_data_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,6 @@ def upload_user_data(request, filename):
# need to get the path and assign it to the dataset as well as pass it to preprocessing function, so I don't
# have to open the db connection before file preprocessing.
file_raw_path = file_serializer.data['get_raw_file_path']
# now I can assign proper storage path
new_dataset.storage_path = file_raw_path
new_dataset.save()

preprocess_file(file_serializer, file_raw_path)

return JsonResponse(file_serializer.data, status=201, safe=False)
Expand Down
4 changes: 2 additions & 2 deletions validator/admin/dataset_custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ class DatasetAdmin(ModelAdmin):
list_display = ('id', 'short_name', 'user', 'file')

def file(self, obj):
if len(obj.user_dataset.all()) and obj.id >= USER_DATASET_MIN_ID:
if len(obj.user_dataset.all()):
return obj.user_dataset.all()[0]
elif obj.id< USER_DATASET_MIN_ID:
return "Application data"
else:
return "No file assigned"
return "No file assigned"
18 changes: 12 additions & 6 deletions validator/models/user_dataset_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ def is_used_in_validation(self):
@property
def owner_validation_list(self):
return [{'val_id': config.validation.pk, 'val_name': config.validation.user_data_panel_label()} for config in
self.get_user_data_configs().filter(validation__user = self.owner)]
self.get_user_data_configs().filter(validation__user=self.owner)]

@property
def number_of_other_users_validations(self):
return len(self.get_user_data_configs().exclude(validation__user = self.owner))
return len(self.get_user_data_configs().exclude(validation__user=self.owner))

@property
def file_size(self):
Expand All @@ -82,17 +82,23 @@ def delete_dataset_file(self):
self.file_name = None
self.save()

def save(self, *args, **kwargs):

self.dataset.storage_path = self.file.path
self.dataset.save()

super(UserDatasetFile, self).save(*args, **kwargs)


@receiver(pre_delete, sender=UserDatasetFile)
def auto_delete_dataset_version_variable(sender, instance, **kwargs):
if instance.dataset:
if instance.dataset and len(instance.dataset.versions.all().exclude(id=instance.version.id)) == 0:
instance.dataset.delete()
if instance.version:
if instance.version and len(instance.version.versions.all()) == 0:
instance.version.delete()
if instance.variable:
if instance.variable and len(instance.variable.variables.all()) == 0:
instance.variable.delete()


@receiver(post_delete, sender=UserDatasetFile)
def auto_delete_file_on_delete(sender, instance, **kwargs):
if instance.file:
Expand Down

0 comments on commit 48dd38e

Please sign in to comment.