Mercurial > genshi > mirror
diff examples/tutorial/geddit/controller.py @ 625:abad7c2ebe15 trunk
GenshiTutorial: implemented AJAX commenting.
author | cmlenz |
---|---|
date | Fri, 31 Aug 2007 17:01:00 +0000 |
parents | 6780f1b1b20d |
children | 3ed77fbfafa8 |
line wrap: on
line diff
--- a/examples/tutorial/geddit/controller.py +++ b/examples/tutorial/geddit/controller.py @@ -10,7 +10,7 @@ from genshi.filters import HTMLFormFiller from geddit.form import LinkForm, CommentForm -from geddit.lib import template +from geddit.lib import ajax, template from geddit.model import Link, Comment @@ -77,14 +77,20 @@ try: data = form.to_python(data) comment = link.add_comment(**data) - raise cherrypy.HTTPRedirect('/info/%s' % link.id) + if not ajax.is_xhr(): + raise cherrypy.HTTPRedirect('/info/%s' % link.id) + return template.render('_comment.html', comment=comment, + num=len(link.comments)) except Invalid, e: errors = e.unpack_errors() else: errors = {} - return template.render(link=link, comment=None, - errors=errors) | HTMLFormFiller(data=data) + if ajax.is_xhr(): + stream = template.render('_form.html', link=link, errors=errors) + else: + stream = template.render(link=link, comment=None, errors=errors) + return stream | HTMLFormFiller(data=data) def main(filename):