Exemple #1
0
def index():
    form = TaskForm(request.form)
    if request.method == 'POST' and form.validate():
        task = {
            'name': form.name.data,
            'deadline': form.deadline.data,
            'done': False
        }
        db.tasks.insert_one(task)
        return redirect(url_for('done'))
    return render_template('index.html', form=form)
Exemple #2
0
    def create_task():
        from app.models import Task
        from app.forms import TaskForm
        # if not request.json or not 'title' in request.json:
        #     abort(400)
        # task = Task(request.json['title'], request.json['description'])
        task_form = TaskForm(**request.json)
        if task_form.validate():
            task = task_form.get_task()
            task.save()
            response = jsonify({
                'id': task.id,
                'title': task.title,
                'description': task.description,
            })
            response.status_code = 201
        else:
            response = jsonify({'errors': task_form.errors})
            response.status_code = 500

        return response
def add_task():
    form = TaskForm(request.form)

    if request.method == "POST" and form.validate():
        # Get task information
        author = session['username']
        description = form.description.data
        status = form.status.data

        # Create a cursor and query the database.
        curr = mysql.connection.cursor()
        curr.execute("INSERT INTO tasks(author, description, status) VALUES(%s, %s, %s)", (author, description, status))
        
        # Commit and close connection.
        mysql.connection.commit()
        curr.close()

        # Flash and redirect back to dashboard.
        flash("Task added.", "success")
        return redirect(url_for("dashboard"))
        
    return render_template("add_task.html", title="Add Task", form=form)