def create(self, blogid): """POST /comments: Create a new item""" # url('comments') create_form = comment_form.bind(Comment, data=request.POST) if create_form.validate(): # Validate captcha if create_form.captcha.value.strip().lower() != "green": return render("/comments/error.html") comment_args = { "referid": blogid, "name": create_form.name.value.strip(), "email": create_form.email.value.strip(), "content": create_form.content.value.strip(), } comment = Comment(**comment_args) Session.add(comment) Session.commit() session["flash"] = "Great success! Your comment was posted." session["flash_class"] = "success" session.save() redirect("/journal/%s" % blogid) blog = Session.query(Blog).filter_by(id=int(blogid)).first() session["flash"] = "There was a problem with your comment." session["flash_class"] = "fail" session.save() return render("/blogs/show.html", {"blog": blog, "comment_form": create_form.render()})
def create(self): """POST /blogs: Create a new item""" # url('blogs') create_form = blog_form.bind(Blog, data=request.POST) if request.POST and create_form.validate(): blog_args = { 'title': create_form.title.value.strip(), 'entry': create_form.entry.value.strip(), 'date': create_form.date.value } blog = Blog(**blog_args) Session.add(blog) Session.commit() redirect('/blogs/show/%s' % blog.id) return render('/blogs/edit.html', { 'blog_form': create_form.render() })