On Tuesday, July 8, 2014 10:19:31 AM UTC-4, Paul Everitt wrote: > > 1) Visually grouping related views. Let's say you have a BlogEntry. It has > a few views. I personally like having a BlogEntryView view class to group > them together. Just an aesthetic point. >
We typically use class methods for shared functionality. In your example of a BlogEntry, the view might have a "main view", in addition to slightly different content for "syndicated" views; it might also be paginated and comments could be in a separate feed to discourage spamming for search-equity. All of these would require a shared "Setup" routine -- so we use the ViewClass to centralize that shared routine. in pseudocode... class BlogPostViews(base): def _setup_post(self): try: self.request.workspace.Post = request params or matchdict into a DB/Cache pull except: redirect to error @viewconfig def main(self): self._setup_post() @viewconfig def syndicated(self): self._setup_post() @viewconfig def paginated(self): self._setup_post() @viewconfig def comments(self): self._setup_post() We also use ViewClasses to handle forms , which typically have 2-3 states [ print/reprint, submit, success(optional) ] : class FormView(base): @viewconfig def access(self): if POST : return self._submit() return self._print() def _print(): return render_to_response('file') def _submit(): try: if not valid: raise redirect( success_url ) except: form_reprint( self.print ) -- You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discuss+unsubscr...@googlegroups.com. To post to this group, send email to pylons-discuss@googlegroups.com. Visit this group at http://groups.google.com/group/pylons-discuss. For more options, visit https://groups.google.com/d/optout.