Пример #1
0
def add_tasks_from_trello(request):
    p = request.user.profile
    trello_key = p.trello_api_key
    trello_secret = p.trello_api_secret

    if request.method == "POST":
        form = AddTrelloIdForm(request.POST)
        if form.is_valid():
            cd = form.cleaned_data
            trello_id = cd["board_id"]

            tasks = get_trello_tasks(board_id=trello_id,
                                     api_key=trello_key,
                                     api_secret=trello_secret)

            for task in tasks:
                t = TodoItem(description=task.name,
                             trello_id=task.board_id,
                             task_id=task.id)
                t.owner = request.user
                t.save()
            return redirect(reverse('list'))
    else:
        form = AddTrelloIdForm()

    return render(request, "tasks/AddTrelloId.html", {"form": form})
Пример #2
0
    def post(self, request, *args, **kwargs):
        form = TodoItemImportTrelloForm(request.POST, )

        if form.is_valid():
            data = form.cleaned_data
            board_id = data['trello_id_board']

            try:
                client = TrelloClient(
                    api_key=request.user.profile.trello_api_key,
                    api_secret=request.user.profile.trello_api_secret)
                desc = client.get_board(board_id)
            except:
                return render(
                    request, 'tasks/import_trello.html', {
                        'form': form,
                        'error':
                        'check your api key and api secret and id board'
                    })
            left_list = desc.list_lists()[0]
            cards = left_list.list_cards()
            for card in cards:
                t = TodoItem(description=card.name,
                             trello_id_board=board_id,
                             trello_id_card=card.id)
                t.owner = request.user
                t.save()

        return redirect(reverse('tasks:list'))
Пример #3
0
 def post(self, request, *args, **kwargs):
     form = TrelloImportForm(request.POST)
     user = request.user
     key = user.profile.trello_key
     secret = user.profile.trello_secret
     if form.is_valid():
         board_id = form.cleaned_data['board_id']
         client = TrelloClient(api_key=key, api_secret=secret)
         board = client.get_board(board_id)
         left_most = board.list_lists()[0]
         # right_most = board.list_lists()[-1]
         todo_tasks = left_most.list_cards()
         for task in todo_tasks:
             t = TodoItem(description=task.name)
             t.owner = user
             t.trello_id = task.id
             t.save()
         messages.success(request, 'Задачи успешно импортированы')
         return redirect(reverse('tasks:list'))
Пример #4
0
def tasks_import(request):
    if request.method == "POST":   #если был переход из формы
        board_id = (request.POST['board_id']) #получаем ID борда
        owner = request.user #получаем пользователя
        prof = Profile.objects.get(user=owner) #получаем профайл пользователя
        key = prof.trello_key #из профайла достаем ключ
        token = prof.trello_token #из профайла достаем токен
        delete_all(owner)
        task_list = get_tasks_from_trello(key, token, board_id) #получаем список тасок из Трелло

        for task in task_list: # сохраняем таски из списка в нашу базу
            import_task = TodoItem()
            import_task.description = task[0]
            import_task.trello_id = task[1]
            import_task.trello_board_id = task[2]
            import_task.owner  = owner
            import_task.save()

        return redirect(reverse("tasks:list"))

    else: #если перешли поссылке, то гененрируем форму
        return render(request, "tasks/import.html")