Exemplo n.º 1
0
def print_task_with_subtask(service: AppService,
                            user,
                            task,
                            indent=4,
                            level=0):
    print(textwrap.indent(str(task), ' ' * indent * level))
    for task in service.get_subtasks(user=user, task_id=task.id):
        print_task_with_subtask(service, user, task, indent, level + 1)
Exemplo n.º 2
0
def task_show_handler(service: AppService, namespace):
    if namespace.show_type == 'id':
        task = service.get_task(user=namespace.user, task_id=namespace.task_id)
        print(task)

    elif namespace.show_type == 'own':
        own_tasks = service.get_own_tasks(user=namespace.user)
        print_collection(own_tasks,
                         mes1='Your own tasks:',
                         mes2='You dont have any tasks')

    elif namespace.show_type == 'subtasks':
        task = service.get_task(namespace.user, task_id=namespace.task_id)
        subtasks = service.get_subtasks(user=namespace.user,
                                        task_id=namespace.task_id)
        if subtasks:
            print_task_with_subtask(service, namespace.user, task)
        else:
            print('Task dont have any subtasks')

    elif namespace.show_type == 'all':
        available_tasks = service.get_available_tasks(user=namespace.user)
        print_collection(available_tasks,
                         mes1='Available tasks:',
                         mes2='You dont have any tasks')

    elif namespace.show_type == 'assigned':
        assigned_tasks = service.get_user_assigned_tasks(user=namespace.user)
        print_collection(assigned_tasks,
                         mes1='Assigned tasks:',
                         mes2='You dont have assigned tasks')

    elif namespace.show_type == 'todo':
        todo_tasks = service.get_filtered_tasks(user=namespace.user,
                                                status=TaskStatus.TODO)
        print_collection(todo_tasks,
                         mes1='Todo tasks:',
                         mes2='You dont have todo tasks')

    elif namespace.show_type == 'inwork':
        inwork_tasks = service.get_filtered_tasks(user=namespace.user,
                                                  status=TaskStatus.INWORK)
        print_collection(inwork_tasks,
                         mes1='Inwork tasks:',
                         mes2='You dont have any inwork tasks')

    elif namespace.show_type == 'done':
        done_tasks = service.get_filtered_tasks(user=namespace.user,
                                                status=TaskStatus.DONE)
        print_collection(done_tasks,
                         mes1='Done tasks:',
                         mes2='You dont have any done tasks')

    elif namespace.show_type == 'archived':
        archived_tasks = service.get_filtered_tasks(user=namespace.user,
                                                    status=TaskStatus.ARCHIVED)
        print_collection(archived_tasks,
                         mes1='Archived tasks:',
                         mes2='You dont have any archived tasks')

    elif namespace.show_type == 'planless':
        planless = [
            task for task in service.get_available_tasks(user=namespace.user)
            if task.plan is None
        ]
        print_collection(planless,
                         mes1='Tasks without plan:',
                         mes2='You dont have any tasks without a plan')