On Jul 4, 2014, at 5:07 AM, SamuraiNinja007 <mr.gro...@gmail.com> wrote:

> I'm mostly just looking for advice and experiences with this question. I'm 
> not looking for advice on my particular case; I'm just curious about when a 
> view callable class has created or relieved stress in the past for others.
> 
> I'm getting to front-end stuff. The web-app I'm working on is quite simple; 
> there will not be a wide variety of pages. I'm considering perhaps making a 
> class for debug-pages and functions, and then having the user-side pages pull 
> from a subclass (or something along those lines). It's hard for me to imagine 
> another good use-case, however.
> 
> Currently, I'm under the impression that, each client-request to a wsgi 
> server is atomized and lacks memory, so a view callable class wouldn't have 
> technical benefits for organizing things such as user session information, 
> although, perhaps it significantly improves workflow?

You are correct that the view class instance isn't a place to hold state. A 
couple of patterns on where it can be useful:

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.

2) Centralizing view settings. If you find yourself repeating some @view_config 
settings on most of your views, you can put a @view_defaults on your class. If 
one or two of your views need something different, you can just override those 
views.

3) Helpers for templates. The view class instance is available in your 
template's namespace. That means you can use the view class for computations 
and other logic that you can call from your template (precomputed in __init__, 
as an attr via @property, as a reified property via @reify, or as a called 
method.)

All 3 of these are for the class of "bigger application" so none of these 
reasons may fit for you. I personally do a view class even when I don't need 
to, because later I need to.

--Paul

-- 
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.

Reply via email to