14799 fix script creation from data-source

This commit is contained in:
Arthur 2024-02-28 07:42:13 -08:00
parent d042e6f69d
commit 04488ff7df
2 changed files with 11 additions and 4 deletions

View File

@ -89,6 +89,9 @@ class ManagedFile(SyncedDataMixin, models.Model):
def clean(self): def clean(self):
super().clean() super().clean()
if self.data_file and not self.file_path:
self.file_path = os.path.basename(self.data_path)
# Ensure that the file root and path make a unique pair # Ensure that the file root and path make a unique pair
if self._meta.model.objects.filter(file_root=self.file_root, file_path=self.file_path).exclude(pk=self.pk).exists(): if self._meta.model.objects.filter(file_root=self.file_root, file_path=self.file_path).exclude(pk=self.pk).exists():
raise ValidationError( raise ValidationError(

View File

@ -137,9 +137,13 @@ class ScriptModule(PythonModuleMixin, JobsMixin, ManagedFile):
Syncs the file-based module to the database, adding and removing individual Script objects Syncs the file-based module to the database, adding and removing individual Script objects
in the database as needed. in the database as needed.
""" """
db_classes = { if self.id:
script.name: script for script in self.scripts.all() db_classes = {
} script.name: script for script in self.scripts.all()
}
else:
db_classes = {}
db_classes_set = set(db_classes.keys()) db_classes_set = set(db_classes.keys())
module_classes_set = set(self.module_scripts.keys()) module_classes_set = set(self.module_scripts.keys())
@ -158,11 +162,11 @@ class ScriptModule(PythonModuleMixin, JobsMixin, ManagedFile):
def sync_data(self): def sync_data(self):
super().sync_data() super().sync_data()
self.sync_classes()
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
self.file_root = ManagedFileRootPathChoices.SCRIPTS self.file_root = ManagedFileRootPathChoices.SCRIPTS
return super().save(*args, **kwargs) return super().save(*args, **kwargs)
self.sync_classes()
@receiver(post_save, sender=ScriptModule) @receiver(post_save, sender=ScriptModule)