Example #1
0
def end_project(project_id):
    """
    Mark the specified project and its component tasks as aborted.

    Args:
        project_id (int): The ID of the project to abort.

    Returns:
        None
    """
    project = Project.objects.get(id=project_id)
    project.status = Project.Status.ABORTED
    project.save()
    for task in project.tasks.all():
        task.status = Task.Status.ABORTED
        task.save()
        notify_status_change(task, assignment_history(task))
        notify_project_status_change(project)
    archive_project_slack_group(project)
Example #2
0
def set_project_status(project_id, status):
    """
    Set the project to the given status. Raise an exception if the status
    is not a valid project status.

    Args:
        project_id (int): The ID of the project
        status (str): The new project status

    Returns:
        None

    Raises:
        orchestra.core.errors.ProjectStatusError:
            The specified new status is not supported.
    """
    project = Project.objects.get(id=project_id)
    status_choices = dict(Project.STATUS_CHOICES)
    if status == status_choices[Project.Status.PAUSED]:
        project.status = Project.Status.PAUSED
        notify_project_status_change(project)
    elif status == status_choices[Project.Status.ACTIVE]:
        project.status = Project.Status.ACTIVE
        notify_project_status_change(project)
    elif status == status_choices[Project.Status.COMPLETED]:
        project.status = Project.Status.COMPLETED
        notify_project_status_change(project)
    elif status == status_choices[Project.Status.ABORTED]:
        raise ProjectStatusError(
            ('Try aborting the project with set_project_status. '
             'Use end_project instead.'))
    else:
        raise ProjectStatusError('Invalid project status.')
    project.save()