def finalize_data(sender, instance, created, raw, update_fields, **kwargs): # Update the projects last edit user when a data is uploaded Project.objects.filter(id=instance.project.id).update( lastedit_user=instance.lastedit_user, lastedit_date=instance.lastedit_date) # Update the project count. instance.project.set_counts() if created: # Generate friendly uid uid = auth.new_uid(obj=instance, objtype=Data, prefix="data") instance.uid = uid # Set the data directory with the recently created uid instance.dir = join(instance.get_project_dir(), f"{instance.uid}") # Set the toc file with the recently created uid instance.toc = join(settings.TOC_ROOT, f"toc-{instance.uid}.txt") # Build the data directory. os.makedirs(instance.dir, exist_ok=True) # Set the table of contents for the data if not os.path.isfile(instance.toc): with open(instance.toc, 'wt') as fp: pass # Update the dir, toc, and uid. Data.objects.filter(id=instance.id).update(uid=instance.uid, dir=instance.dir, toc=instance.toc) instance.make_toc()
def finalize_project(sender, instance, created, raw, update_fields, **kwargs): if created: # Generate friendly uid uid = auth.new_uid(obj=instance, objtype=Project, prefix="project") instance.uid = uid instance.label = uid # Set the project directory instance.dir = instance.dir or join(settings.MEDIA_ROOT, "projects", f"{instance.uid}") # Create the job directory if it does not exist. os.makedirs(instance.dir, exist_ok=True) # Update project fields. Project.objects.filter(id=instance.id).update(uid=instance.uid, label=instance.label, dir=instance.dir) # Create a starter recipe if none exist if not instance.analysis_set.exists(): initial_recipe(project=instance) # Cascade deleted states to recipe, data, and results. if instance.deleted: Analysis.objects.filter(project__id=instance.pk).update(deleted=True) Data.objects.filter(project__id=instance.pk).update(deleted=True) Job.objects.filter(project__id=instance.pk).update(deleted=True)
def finalize_recipe(sender, instance, created, raw, update_fields, **kwargs): if created: # Generate friendly uid uid = auth.new_uid(obj=instance, objtype=Analysis, prefix="recipe") instance.uid = uid Analysis.objects.filter(id=instance.id).update(uid=instance.uid) # Update the last edit date and user of project user = instance.lastedit_user # Strip json text of 'settings' parameter instance.json_text = strip_json(instance.json_text) Project.objects.filter(id=instance.project.id).update( lastedit_date=instance.lastedit_date, lastedit_user=user) # Update information of all children belonging to this root. if instance.is_root: instance.update_children() # Update root information belonging to this child else: instance.update_root() # Update the project count and last edit date when job is created instance.project.set_counts()
def finalize_project(sender, instance, created, raw, update_fields, **kwargs): if created: # Generate friendly uid uid = auth.new_uid(obj=instance, objtype=Project, prefix="project") instance.uid = uid # Set the project directory instance.dir = instance.dir or join(settings.MEDIA_ROOT, "projects", f"{instance.uid}") # Get project with highest rank and add to it, # ensuring this new project is at the top of lists first = Project.objects.order_by('-rank').first() instance.rank = first.rank + instance.pk if first else instance.pk # Create the job directory if it does not exist. os.makedirs(instance.dir, exist_ok=True) # Update project fields. Project.objects.filter(id=instance.id).update(uid=instance.uid, dir=instance.dir, rank=instance.rank) # Create a starter recipe if none exist. if not instance.analysis_set.exists(): initial_recipe(project=instance) # Cascade deleted states to recipe, data, and results. if instance.deleted: Analysis.objects.filter(project__id=instance.pk).update(deleted=True) Data.objects.filter(project__id=instance.pk).update(deleted=True) Job.objects.filter(project__id=instance.pk).update(deleted=True)
def finalize_recipe(sender, instance, created, raw, update_fields, **kwargs): if created: # Generate friendly uid uid = auth.new_uid(obj=instance, objtype=Analysis, prefix="recipe") instance.uid = uid Analysis.objects.filter(id=instance.id).update(uid=instance.uid) # Get recipe with highest rank and add to it, # ensuring this new recipe is at the top of lists first = Analysis.objects.order_by('-rank').first() instance.rank = first.rank + instance.pk if first else instance.pk # Update the last edit date and user of project user = instance.lastedit_user # Strip json text of 'settings' parameter instance.json_text = strip_json(instance.json_text) Project.objects.filter(id=instance.project.id).update( lastedit_date=instance.lastedit_date, lastedit_user=user) # Update information of all children belonging to this root. if instance.is_root: instance.update_children() # Update the project count and last edit date when job is created instance.project.set_counts()
def finalize_job(sender, instance, created, raw, update_fields, **kwargs): # Update the project count. instance.project.set_counts() if created: # Generate friendly uid uid = auth.new_uid(obj=instance, objtype=Job, prefix="job") instance.uid = uid # Generate the path based on the instance.path = join(settings.MEDIA_ROOT, "jobs", f"{instance.uid}") # Create the job directory if it does not exist. os.makedirs(instance.path, exist_ok=True) # Update the information in db. Job.objects.filter(id=instance.id).update(uid=instance.uid, path=instance.path)
def finalize_project(sender, instance, created, raw, update_fields, **kwargs): if created: # Generate friendly uid uid = auth.generate_uuid(prefix="project", suffix=instance.id) uid = auth.new_uid(obj=instance, objtype=Project, default=uid) instance.uid = uid instance.label = uid # Set the project directory instance.dir = instance.dir or join(settings.MEDIA_ROOT, "projects", f"{instance.uid}") # Create the job directory if it does not exist. os.makedirs(instance.dir, exist_ok=True) # Update project fields. Project.objects.filter(id=instance.id).update(uid=instance.uid, label=instance.label, dir=instance.dir) # Create a starter recipe if none exist if not instance.analysis_set.exists(): initial_recipe(project=instance)