(self, *args)
| 35 | public_id = models.UUIDField(db_index=True, default=None, unique=True, blank=True, null=True, help_text=_("Public identifier of the project"), verbose_name=_("Public Id")) |
| 36 | |
| 37 | def delete(self, *args): |
| 38 | # No tasks? |
| 39 | if not self.task_set.exists(): |
| 40 | # Just delete normally |
| 41 | |
| 42 | project_dir = self.get_project_dir() |
| 43 | if os.path.isdir(project_dir): |
| 44 | entries = os.listdir(project_dir) |
| 45 | empty_project_folder = False |
| 46 | |
| 47 | if len(entries) == 0: |
| 48 | empty_project_folder = True |
| 49 | elif len(entries) == 1 and entries[0] == "task": |
| 50 | empty_project_folder = len(os.listdir(os.path.join(project_dir, "task"))) == 0 |
| 51 | |
| 52 | if empty_project_folder: |
| 53 | logger.info(f"Deleting {project_dir}") |
| 54 | try: |
| 55 | shutil.rmtree(project_dir) |
| 56 | except Exception as e: |
| 57 | logger.warning(f"Cannot delete {project_dir}: {str(e)}") |
| 58 | else: |
| 59 | logger.warning(f"Project {self.id} is being deleted, but data is stored on disk. We will keep the data at {project_dir}, but will become orphaned") |
| 60 | |
| 61 | logger.info("Deleted project {}".format(self.id)) |
| 62 | |
| 63 | super().delete(*args) |
| 64 | else: |
| 65 | # Need to remove all tasks before we can remove this project |
| 66 | # which will be deleted by workers after pending actions |
| 67 | # have been completed |
| 68 | self.task_set.update(pending_action=pending_actions.REMOVE) |
| 69 | self.deleting = True |
| 70 | self.save() |
| 71 | logger.info("Tasks pending, set project {} deleting flag".format(self.id)) |
| 72 | |
| 73 | def __str__(self): |
| 74 | return self.name |
nothing calls this directly
no test coverage detected