Beispiel #1
0
def get_project_and_minimum_priority(
    session: Session,
    project: t.Union[str, int, None],
    minimum_priority: t.Union[str, int, None],
    ignore_priority: bool = False,
) -> t.Tuple[t.Optional[models.Project], t.Optional[int]]:
    project = (None if project == 'all' else
               models.Project.get_for_identifier_or_raise(
                   session,
                   project,
                   schemas.ProjectSchema(),
               ))
    level = None

    if not ignore_priority:
        if project is None:
            if minimum_priority is not None:
                if not isinstance(minimum_priority, int):
                    raise SimpleError(
                        'When filtering on priority levels for multiple projects, level just be specified as an int'
                    )
                level = minimum_priority

        else:
            if minimum_priority is not None:
                level = get_priority_level(session, minimum_priority, project)
            elif project.default_priority_filter is not None:
                level = project.default_priority_filter

    return project, level
Beispiel #2
0
def project_list():
    projects: t.List[models.ToDo] = SC.session.query(models.Project).order_by(models.Project.created_at.desc())

    schema = schemas.ProjectSchema()

    return {
        'projects': [
            schema.serialize(project)
            for project in
            projects
        ]
    }
Beispiel #3
0
def create_todo():
    schema = ToDoSchema()

    try:
        todo_data = schema.deserialize_raw(request.data)
        create_data = schemas.CreateTodoSchema().deserialize_raw(request.data)
    except DeserializationError as e:
        return e.serialized, status.HTTP_400_BAD_REQUEST

    project = models.Project.get_for_identifier_or_raise(
        SC.session,
        create_data.get('project'),
        schemas.ProjectSchema(),
    )
    todo_data['project_id'] = project.id

    priority = models.Priority.get_for_identifier_or_raise(
        session=SC.session,
        identifier=create_data.get('priority'),
        schema=schemas.PrioritySchema(),
        base_query=SC.session.query(
            models.Priority).filter(models.Priority.project_id == project.id))

    todo_data['priority_id'] = priority.id

    todo = models.ToDo(**todo_data)

    for tag in create_data['tags']:
        todo.tags.append(
            models.Tag.get_for_identifier_or_raise(
                SC.session,
                tag,
                schemas.TagSchema(),
            ))

    for parent in create_data['parents']:
        parent = get_todo_for_project_and_identifier(SC.session, parent,
                                                     project)
        todo.parents.append(parent)

    SC.session.add(todo)

    SC.session.commit()

    return schema.serialize(todo)
Beispiel #4
0
def create_project():
    schema = schemas.ProjectSchema()

    try:
        project = schema.deserialize(request.data)
    except DeserializationError as e:
        return e.serialized, status.HTTP_400_BAD_REQUEST

    if project.is_default:
        SC.session.query(models.Project).update({models.Project.is_default: False}, synchronize_session = False)

    SC.session.add(project)

    try:
        SC.session.commit()
    except IntegrityError:
        SC.session.rollback()
        return 'Project already exists', status.HTTP_400_BAD_REQUEST

    return schema.serialize(project)
Beispiel #5
0
def modify_project(project: models.Project, default_priority_filter: t.Union[int, str, None]):
    if default_priority_filter is not None:
        default_priority_filter = get_priority_level(SC.session, default_priority_filter, project)
    project.default_priority_filter = default_priority_filter
    SC.session.commit()
    return schemas.ProjectSchema().serialize(project)