Mercurial > genshi > mirror
comparison examples/tutorial/geddit/controller.py @ 615:06165fee45ab trunk
GenshiTutorial: make URLs dynamic so that the app could theoretically be mounted on some other SCRIPT_NAME.
author | cmlenz |
---|---|
date | Wed, 29 Aug 2007 20:12:54 +0000 |
parents | 1e6cf366b944 |
children | 8ada29c99c0d |
comparison
equal
deleted
inserted
replaced
613:1e6cf366b944 | 615:06165fee45ab |
---|---|
28 for reply in comment.replies: | 28 for reply in comment.replies: |
29 self._comment_lookup[reply.code] = reply | 29 self._comment_lookup[reply.code] = reply |
30 _add_replies(comment) | 30 _add_replies(comment) |
31 | 31 |
32 @cherrypy.expose | 32 @cherrypy.expose |
33 @template.output('index.html', method='html', doctype='html') | 33 @template.output('index.html') |
34 def index(self): | 34 def index(self): |
35 return template.render(submissions=self.data) | 35 return template.render(submissions=self.data) |
36 | 36 |
37 @cherrypy.expose | 37 @cherrypy.expose |
38 @template.output('info.html', method='html', doctype='html') | 38 @template.output('info.html') |
39 def info(self, code): | 39 def info(self, code): |
40 submission = self._submission_lookup.get(code) | 40 submission = self._submission_lookup.get(code) |
41 if not submission: | 41 if not submission: |
42 raise cherrypy.NotFound() | 42 raise cherrypy.NotFound() |
43 return template.render(submission=submission) | 43 return template.render(submission=submission) |
44 | 44 |
45 @cherrypy.expose | 45 @cherrypy.expose |
46 @template.output('submit.html', method='html', doctype='html') | 46 @template.output('submit.html') |
47 def submit(self, cancel=False, **data): | 47 def submit(self, cancel=False, **data): |
48 if cherrypy.request.method == 'POST': | 48 if cherrypy.request.method == 'POST': |
49 if cancel: | 49 if cancel: |
50 raise cherrypy.HTTPRedirect('/') | 50 raise cherrypy.HTTPRedirect('/') |
51 form = SubmissionForm() | 51 form = SubmissionForm() |
61 errors = {} | 61 errors = {} |
62 | 62 |
63 return template.render(errors=errors) | HTMLFormFiller(data=data) | 63 return template.render(errors=errors) | HTMLFormFiller(data=data) |
64 | 64 |
65 @cherrypy.expose | 65 @cherrypy.expose |
66 @template.output('comment.html', method='html', doctype='html') | 66 @template.output('comment.html') |
67 def comment(self, code, cancel=False, **data): | 67 def comment(self, code, cancel=False, **data): |
68 submission = self._submission_lookup.get(code) | 68 submission = self._submission_lookup.get(code) |
69 if not submission: | 69 if not submission: |
70 raise cherrypy.NotFound() | 70 raise cherrypy.NotFound() |
71 if cherrypy.request.method == 'POST': | 71 if cherrypy.request.method == 'POST': |
74 form = CommentForm() | 74 form = CommentForm() |
75 try: | 75 try: |
76 data = form.to_python(data) | 76 data = form.to_python(data) |
77 comment = submission.add_comment(**data) | 77 comment = submission.add_comment(**data) |
78 self._comment_lookup[comment.code] = comment | 78 self._comment_lookup[comment.code] = comment |
79 raise cherrypy.HTTPRedirect('/') | 79 raise cherrypy.HTTPRedirect('/info/%s' % submission.code) |
80 except Invalid, e: | 80 except Invalid, e: |
81 errors = e.unpack_errors() | 81 errors = e.unpack_errors() |
82 else: | 82 else: |
83 errors = {} | 83 errors = {} |
84 | 84 |
85 return template.render(submission=submission, comment=None, | 85 return template.render(submission=submission, comment=None, |
86 errors=errors) | 86 errors=errors) |
87 | 87 |
88 @cherrypy.expose | 88 @cherrypy.expose |
89 @template.output('comment.html', method='html', doctype='html') | 89 @template.output('comment.html') |
90 def reply(self, code, cancel=False, **data): | 90 def reply(self, code, cancel=False, **data): |
91 comment = self._comment_lookup.get(code) | 91 comment = self._comment_lookup.get(code) |
92 submission = comment.submission | 92 submission = comment.submission |
93 if not comment: | 93 if not comment: |
94 raise cherrypy.NotFound() | 94 raise cherrypy.NotFound() |
98 form = CommentForm() | 98 form = CommentForm() |
99 try: | 99 try: |
100 data = form.to_python(data) | 100 data = form.to_python(data) |
101 comment = comment.add_reply(**data) | 101 comment = comment.add_reply(**data) |
102 self._comment_lookup[comment.code] = comment | 102 self._comment_lookup[comment.code] = comment |
103 raise cherrypy.HTTPRedirect('/') | 103 raise cherrypy.HTTPRedirect('/info/%s' % submission.code) |
104 except Invalid, e: | 104 except Invalid, e: |
105 errors = e.unpack_errors() | 105 errors = e.unpack_errors() |
106 else: | 106 else: |
107 errors = {} | 107 errors = {} |
108 | 108 |