Exemple #1
0
def add_todo():
    title = request.form['title']
    if not title:
        return render_template('error.html', content="标题是必须的",url=None)
    db = todo.db.get_db()
    db.execute('insert into todo (title, post_date) values (?, ?)',
                   [title, datetime.now()])
    db.commit()
    flash('New entry was successfully posted')
    return redirect(url_for('show_todos'))
Exemple #2
0
def add_todo():
    title = request.form['title']
    if not title:
        return render_template('error.html', content="标题是必须的", url=None)
    db = todo.db.get_db()
    db.execute('insert into todo (title, post_date) values (?, ?)',
               [title, datetime.now()])
    db.commit()
    flash('New entry was successfully posted')
    return redirect(url_for('show_todos'))
Exemple #3
0
def edit(id):
    onetodo = get_by_id(id)
    if not onetodo:
        return render_template('error.html', content="没找到这条记录", url=None)
    if request.method == 'GET':
        return render_template('todo/edit.html', todo=onetodo, app=app)
    else:
        title = request.form['title']
        if not title:
            return render_template('error.html', content="标题是必须的", url=None)
        db = todo.db.get_db()
        db.execute('update todo set title=? where id=?', [title, id])
        db.commit()
        flash('Edit todo was successfully posted')
        return redirect(url_for('show_todos'))
Exemple #4
0
def finish(id):
    if not todo:
        return render_template('error.html', content="没找到这条记录", url=None)
    status = request.args.get('status')
    if status == 'yes':
        finished = 1
    elif status == 'no':
        finished = 0
    else:
        return render_template('error.html', content="您发起了一个不允许的请求", url='/')
    db = todo.db.get_db()
    db.execute('update todo set finished=? where id=?', [finished, id])
    db.commit()
    flash('New entry was successfully posted')
    return redirect(url_for('show_todos'))
Exemple #5
0
def get_by_id(id):
    db = todo.db.get_db()
    cur = db.execute('select * from todo where id=?', [id])
    s = cur.fetchone()
    if not s:
        return False
    return s
Exemple #6
0
def get_by_id(id):
    db = todo.db.get_db()
    cur = db.execute('select * from todo where id=?',[id])
    s = cur.fetchone()
    if not s:
        return False
    return s
Exemple #7
0
def edit(id):
    onetodo = get_by_id(id)
    if not onetodo:
        return render_template('error.html', content="没找到这条记录",url=None)
    if request.method == 'GET':
        return render_template('todo/edit.html', todo=onetodo, app=app)
    else:
        title = request.form['title']
        if not title:
            return render_template('error.html', content="标题是必须的",url=None)
        db = todo.db.get_db()
        db.execute('update todo set title=? where id=?',
                       [title, id])
        db.commit()
        flash('Edit todo was successfully posted')
        return redirect(url_for('show_todos'))
Exemple #8
0
def finish(id):
    if not todo:
        return render_template('error.html', content="没找到这条记录",url=None)
    status = request.args.get('status')
    if status == 'yes':
        finished = 1
    elif status == 'no':
        finished = 0
    else:
        return render_template('error.html', content="您发起了一个不允许的请求",url='/')
    db = todo.db.get_db()
    db.execute('update todo set finished=? where id=?',
                   [finished, id])
    db.commit()
    flash('New entry was successfully posted')
    return redirect(url_for('show_todos'))
Exemple #9
0
def delete(id):
    if not todo:
        return render_template('error.html', content="没找到这条记录", url=None)
    db = todo.db.get_db()
    db.execute('delete from todo where id=?', [id])
    return render_template('error.html', content="删除成功!", url='/')
Exemple #10
0
def show_todos():
    db = todo.db.get_db()
    cur = db.execute('select * from todo order by finished asc, id asc')
    todos = cur.fetchall()
    return render_template('index.html', todos=todos, app=app)
Exemple #11
0
def delete(id):
    if not todo:
        return render_template('error.html', content="没找到这条记录",url=None)
    db = todo.db.get_db()
    db.execute('delete from todo where id=?',[id])
    return render_template('error.html', content="删除成功!",url='/')
Exemple #12
0
def show_todos():
    db = todo.db.get_db()
    cur = db.execute('select * from todo order by finished asc, id asc')
    todos = cur.fetchall()
    return render_template('index.html', todos=todos, app=app)