52 """ |
52 """ |
53 |
53 |
54 # MultiDict from werkzeug.Request |
54 # MultiDict from werkzeug.Request |
55 return self.request.form |
55 return self.request.form |
56 |
56 |
57 def respond (self, url_values) : |
57 def respond (self, **url_values) : |
58 """ |
58 """ |
59 Handle request that was mapped to ourselves via the URL routing, using given dict of values from URL. |
59 Handle request that was mapped to ourselves via the URL routing, using given dict of values from URL. |
60 """ |
60 """ |
61 |
61 |
62 raise NotImplementedError() |
62 # process e.g. POST data for e.g. redirect |
|
63 response = self.process(**url_values) |
|
64 |
|
65 if not response : |
|
66 # assume superclass does something else if process didn't handle it |
|
67 pass |
|
68 |
|
69 return response |
|
70 |
|
71 def process (self, **args) : |
|
72 """ |
|
73 Process incoming POST data, optionally returning a redirect response. |
|
74 """ |
|
75 |
|
76 # default to ignore |
|
77 pass |
63 |
78 |
64 class PageHandler (AppHandler) : |
79 class PageHandler (AppHandler) : |
65 """ |
80 """ |
66 Specialized AppHandler for normal HTML page views. |
81 Specialized AppHandler for normal HTML page views. |
67 |
82 |
153 response = self.render_layout(content) |
168 response = self.render_layout(content) |
154 |
169 |
155 # ok |
170 # ok |
156 return response |
171 return response |
157 |
172 |
158 def respond (self, url_values) : |
173 def respond (self, **url_values) : |
159 """ |
174 """ |
160 Build and return a response from the following steps: |
175 Build and return a response from the following steps: |
161 |
176 |
162 * process() |
177 * process() |
163 * render() -> render_content() as HTML |
178 * render() -> render_content() as HTML |
164 """ |
179 """ |
165 |
180 |
166 # process e.g. POST data for e.g. redirect |
181 # optional processing |
167 response = self.process(**url_values) |
182 response = super(PageHandler, self).respond(**url_values) |
168 |
183 |
169 if not response : |
184 if not response : |
170 # render page HTML |
185 # render page HTML |
171 html = self.render(**url_values) |
186 html = self.render(**url_values) |
172 |
187 |
175 return Response(html, mimetype='text/html') |
190 return Response(html, mimetype='text/html') |
176 |
191 |
177 # ok |
192 # ok |
178 return response |
193 return response |
179 |
194 |
180 def process (self, **args) : |
|
181 """ |
|
182 Process incoming POST data, optionally returning a redirect response. |
|
183 """ |
|
184 |
|
185 # default to ignore |
|
186 pass |
|
187 |
|
188 class DocumentHandler (AppHandler) : |
195 class DocumentHandler (AppHandler) : |
189 """ |
196 """ |
190 PDF generation/export |
197 PDF generation/export |
191 """ |
198 """ |
192 |
199 |
193 def respond (self, url_values) : |
200 def respond (self, **url_values) : |
194 """ |
201 """ |
195 Generate the document, and return it as a .pdf file, with the filename generated from the document's title. |
202 Generate the document, and return it as a .pdf file, with the filename generated from the document's title. |
196 """ |
203 """ |
197 |
204 |
198 # XXX: proper support |
205 # optional processing |
199 self.process(**url_values) |
206 response = super(DocumentHandler, self).respond(**url_values) |
200 |
207 |
201 pdf_file = self.generate(**url_values) |
208 if not response : |
202 |
209 pdf_file = self.generate(**url_values) |
203 # file wrapper |
210 |
204 # XXX: is this any use at all for StringIO? |
211 # file wrapper |
205 pdf_file = werkzeug.wrap_file(self.request.environ, pdf_file) |
212 # XXX: is this any use at all for StringIO? |
206 |
213 pdf_file = werkzeug.wrap_file(self.request.environ, pdf_file) |
207 # respond with file wrapper |
214 |
208 return Response(pdf_file, mimetype='application/pdf', direct_passthrough=True) |
215 # respond with file wrapper |
|
216 response = Response(pdf_file, mimetype='application/pdf', direct_passthrough=True) |
|
217 |
|
218 # ok |
|
219 return response |
209 |
220 |
210 def generate (self, **url_values) : |
221 def generate (self, **url_values) : |
211 """ |
222 """ |
212 Generate the PDF document as a file-like object. |
223 Generate the PDF document as a file-like object. |
213 """ |
224 """ |