Exemplo n.º 1
0
def task_delete(task_id):
    if not current_user.is_authenticated:
        return is_not_auth()

    # if False:
    #     abort(404)

    if request.method == "GET":
        task = Task.filter(Task.id == task_id).first()

        if task is None:
            return abort(404)

        form = TaskDeleteForm(formdata=request.form, obj=task)
        content = render_form(form=form,
                              action=url_for("task_delete"),
                              delete=True)

        return render_content(
            content, "Вы уверены что хотите удалить - {}?".format(task.title))

    if request.method == 'POST':
        task = Task.get(Task.id == request.form["id"])
        var_dump(task)
        task.delete()
        flash('Событие <b><em>{}</em></b> успешно удалено'.format(task.title),
              'success')
        return redirect(url_for('task_list'))
Exemplo n.º 2
0
def task_edit(task_id):
    if not current_user.is_authenticated:
        return is_not_auth()

    task = Task.get(Task.id == task_id)

    form = TaskForm(formdata=request.form, obj=task)

    if request.method == "GET":
        content = render_form(form=form,
                              action=url_for("task_edit", task_id=task_id),
                              button="Обновить")

        return render_content(content, "Редактировать - {}".format(task.title))

    if request.method == 'POST' and form.validate():
        title = request.form['title']
        description = request.form['description']
        date = request.form['date']
        time = request.form['time']

        task.title = title
        task.description = description
        task.date = date
        task.user = current_user.id
        task.time = time
        task.save()

        flash('Задание <b><em>{}</em></b> успешно обновлено'.format(title),
              'success')
        return redirect(url_for('task_list'))
Exemplo n.º 3
0
def task_change_status(task_id):
    if not current_user.is_authenticated:
        return is_not_auth()

    task = Task.get(Task.id == task_id)

    form = TaskStatusForm(formdata=request.form, obj=task)

    if request.method == "GET":
        content = render_form(form=form,
                              action=url_for("task_change_status",
                                             task_id=task_id),
                              button="Обновить")

        return render_content(content,
                              "Изменить статус - {}".format(task.title))

    if request.method == 'POST' and form.validate():
        status = request.form['status']
        task.status = status
        task.save()

        flash('Статус <b><em>{}</em></b> успешно обновлен'.format(task.title),
              'success')
        return redirect(url_for('task_list'))
Exemplo n.º 4
0
def task_create():

    if not current_user.is_authenticated:
        return is_not_auth()

    form = TaskForm(request.form)

    if request.method == 'POST' and form.validate():
        title = request.form['title']
        description = request.form['description']
        date = request.form['date']
        time = request.form['time']

        Task.create(title=title,
                    description=description,
                    date=date,
                    user=current_user.id,
                    time=time)

        flash('Задание успешно добавлено', 'success')
        return redirect(url_for('task_list'))

    content = render_form(form=form,
                          action=url_for("task_create"),
                          button="Создать")

    return render_content(content, "Создать задание")
Exemplo n.º 5
0
def task_list():
    if not current_user.is_authenticated:
        return is_not_auth()

    tasks = Task.select() \
        .order_by(Task.date) \
        .where(Task.user == current_user.id)

    content = render_tasks_list_as_table(tasks)
    return render_content(content, "Список дел")