def delete(id): if require_login(): return redirect(url_for(login)) n = blogs.get(blogs.c.id == id) if n: n.delete() return redirect('/');
def edit(id): if require_login(): return redirect(url_for(login)) if request.method == 'GET': p = blogs.get(blogs.c.id==id) form = BlogsForm(data={'title':p.title,'content':p.content}) return {'form':form} elif request.method == 'POST': form = BlogsForm() flag = form.validate(request.params) n = blogs.get(blogs.c.id == id) if n: n.username = request.user.username n.title = form.data.title n.content = form.data.content n.save() return redirect('/');
def view(id): if request.method == "GET": info = blogs.get(blogs.c.id == id) form = CommentsForm() comment = comments.filter(comments.c.blog_id == id) return {'form':form, 'info':info, 'comment':comment} if request.method == "POST": form = CommentsForm() flag = form.validate(request.params) if flag: info = comments(**form.data) info.blog_id = id info.save() return redirect('/view/%s' % id)