| 7 | |
| 8 | @dataclass |
| 9 | class Task_Update(): |
| 10 | session: any |
| 11 | task: Task |
| 12 | mode: str = None |
| 13 | status: str = None |
| 14 | member: 'Member' = None |
| 15 | |
| 16 | """ |
| 17 | Controls the changing of the task status and generation of the appropriate events depending |
| 18 | on the status. |
| 19 | |
| 20 | Notes: |
| 21 | - For completing a task use task_complete() function in task.py. that function uses this class eventually. |
| 22 | |
| 23 | """ |
| 24 | |
| 25 | def __post_init__(self): |
| 26 | |
| 27 | self.session.add(self.task) |
| 28 | self.try_to_commit = regular_methods.try_to_commit |
| 29 | |
| 30 | # TODO clarify if this needs to use factory thing |
| 31 | self.log = regular_log.default() |
| 32 | |
| 33 | def main(self): |
| 34 | old_status = self.task.status |
| 35 | if self.mode == 'toggle_deferred': |
| 36 | self.defer() |
| 37 | if self.mode == 'incomplete': |
| 38 | self.status = 'in_progress' |
| 39 | self.change_status() |
| 40 | if self.status: |
| 41 | self.change_status() |
| 42 | regular_methods.try_to_commit(self) |
| 43 | self.emit_task_event_based_on_status(old_status, self.task) |
| 44 | self.update_related_file_status(old_status, self.task) |
| 45 | self.task.job.refresh_stat_count_tasks(self.session) |
| 46 | return |
| 47 | |
| 48 | def update_related_file_status(self, old_status, updated_task: Task): |
| 49 | if updated_task.status == 'complete': |
| 50 | # Find All Other Tasks from the related file |
| 51 | other_pending_tasks = Task.get_related_pending_tasks(session = self.session, |
| 52 | task = updated_task) |
| 53 | if len(other_pending_tasks) == 0: |
| 54 | updated_task.file.ann_is_complete = True |
| 55 | |
| 56 | else: |
| 57 | updated_task.file.ann_is_complete = False |
| 58 | else: |
| 59 | updated_task.file.ann_is_complete = False |
| 60 | self.session.add(updated_task.file) |
| 61 | |
| 62 | def emit_task_event_based_on_status(self, old_status, task): |
| 63 | if task.status == 'complete': |
| 64 | if old_status != 'completed': |
| 65 | assignees = task.get_assignees(session = self.session) |
| 66 | if old_status == 'in_review': |
no outgoing calls