Mike Orr wrote:
> On Mon, Apr 5, 2010 at 6:36 AM, Tim Black <[email protected]> wrote:
>   
>> I'm beginning to think that when I write controllers named things like
>> getTaskHTML() or setTaskHTML() when I have a model.Task object but it
>> doesn't have an attribute named HTML, I should refactor those methods to
>> this form:  model.Task.HTML where HTML is a Python property or is accessible
>> via __setattr__ and __getattribute__.  In general, if I'm writing controller
>> methods that are merely basic manipulations of model objects, I'm thinking I
>> should put those methods into the model rather than the controller.  Is that
>> correct?
>>     
>
> Philosophically, the model shouldn't have any  structural (WSGI- or
> HTTP-specific) or UI (HTML-specific)  code in it.  The input values
> are coming from POST parameters, which the model shouldn't know about.
>  The model should make sense outside a web context.  So there should
> be at least a thin layer validating/translating the input to generic
> arguments.
>   
I agree.  I should have used a more appropriate example--the one I'm
working on right now is that I have a model class named Task which
contains tasks arranged in a tree structure represented by means of a
column named "parent" which contains the parent task's id.  I'm
displaying the total of the estimated and actual hours for that task by
adding up those columns for all of each task's children.  So, instead of
my current controller methods named getTaskEstimatedHours() and
setTaskEstimatedHours(), because the values those methods return can
naturally be conceived of as attributes of a model object instance, I
think I should put those methods under an accessor named
model.Task.estimated_hours.  At first I left such methods out of the
model, but now I'm thinking it's better to put them in the model to make
the controllers less cluttered.  Is that a wise direction to go?

Tim Black

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.

Reply via email to