def get_project_task_data(project_id): project = Project.objects.get(id=project_id) tasks = {} for task in project.tasks.all(): tasks[task.step.slug] = TaskSerializer(task).data return tasks
def _expected_audit(self, complete_task, reverted_status=None, assignment_changes=None, iteration_changes=None): assignments = assignment_history(complete_task) iterations = get_iteration_history(complete_task) audit = { 'task': TaskSerializer(complete_task).data, 'assignments': [{ 'assignment': (TaskAssignmentSerializer(assignments.first()).data), 'change': 0, 'iterations': [{ 'change': 0, 'iteration': (IterationSerializer(iterations.all()[0]).data) }, { 'change': 0, 'iteration': (IterationSerializer(iterations.all()[2]).data) }] }, { 'assignment': (TaskAssignmentSerializer(assignments.last()).data), 'change': 0, 'iterations': [{ 'change': 0, 'iteration': (IterationSerializer(iterations.all()[1]).data) }, { 'change': 0, 'iteration': (IterationSerializer(iterations.all()[3]).data) }] }], } if reverted_status is not None: audit['reverted_status'] = reverted_status if assignment_changes is not None: for i, assignment_change in enumerate(assignment_changes): audit['assignments'][i]['change'] = assignment_change if iteration_changes is not None: for i, changes_per_assignment in enumerate(iteration_changes): for j, iteration_change in enumerate(changes_per_assignment): audit['assignments'][i]['iterations'][j][ 'change'] = iteration_change return audit
def _build_revert_audit(task, revert_iteration, revert_before): if task.status == Task.Status.ABORTED: raise InvalidRevertError('Cannot revert aborted task.') task_audit = { 'task': TaskSerializer(task).data, 'assignments': [], } for assignment in assignment_history(task).all(): assignment_audit = (_build_assignment_revert_audit( assignment, revert_iteration, revert_before)) task_audit['assignments'].append(assignment_audit) task_audit['reverted_status'] = _reverted_task_status( task_audit, revert_before) return task_audit
def get_project_information(project_ids): """ output format: { project_id: { 'project': serialized_project_data, 'tasks': project_tasks_list, 'steps': project_workflow_steps }, ... } Example: { 123: { 'project': {}, 'tasks': [], 'steps': [] }, ... } """ projects = Project.objects.select_related( 'workflow_version__workflow').filter( id__in=project_ids).prefetch_related('tasks') projects_dict = defaultdict(dict) for project in projects: project_id = project.id workflow_version = project.workflow_version workflow = workflow_version.workflow projects_dict[project_id]['project'] = ProjectSerializer(project).data projects_dict[project_id]['steps'] = get_workflow_steps( workflow.slug, workflow_version.slug) tasks = defaultdict(dict) for task in project.tasks.all(): tasks[project.id][task.step.slug] = TaskSerializer(task).data projects_dict[project_id]['tasks'] = tasks.get(project_id, {}) return projects_dict
def revert_task_to_datetime(task_id, revert_datetime, fake=False): """ Reverts a task to its state immediately before the specified datetime. Args: task_id (int): The ID of the task to be reverted. revert_datetime (datetime.datetime): The datetime before which to revert the task. fake (bool): Determines whether the revert is actually carried out; otherwise, an audit trail is passively generated. Returns: audit (dict): An audit trail for the revert, e.g., { 'task': {...}, 'change': 'reverted' 'assignments': [ { # worker_0 assignment 'assignment': {...}, 'change': 'reverted', 'snapshots': [ { 'snapshot': {...}, 'change': 'unchanged' } { 'snapshot': {...}, 'change': 'deleted' }, ] }, { # worker_1 assignment 'assignment': {...}, 'change': 'deleted', 'snapshots': [ { 'snapshot': {...}, 'change': 'deleted' }, { 'snapshot': {...}, 'change': 'deleted' } ] } ], } """ task = Task.objects.get(id=task_id) audit = { 'task': TaskSerializer(task).data, 'change': 'unchanged', 'assignments': [] } reverted = False for assignment in assignment_history(task).all(): assignment_audit = _revert_assignment_to_datetime( assignment, revert_datetime, fake) audit['assignments'].append(assignment_audit) if assignment_audit['change'] != 'unchanged': reverted = True # Delete task if it starts after revert_datetime if task.start_datetime >= revert_datetime: audit['change'] = 'deleted' if not fake: task.delete() elif reverted: audit['change'] = 'reverted' if not fake: _revert_task_status(task) return audit