On Wed, Jun 6, 2012 at 4:10 AM, Vlad K. <[email protected]> wrote:
> On 06/06/2012 09:50 AM, tanshu wrote:
>>
>> Hi,
>> I am sorry if this has been asked before, but I couldn't find the answer
>> anywhere.  I am relatively new to python / pyramid and have developed a few
>> test programs.  I come from a C# background and could not figure out what
>> the best pattern is to lay out database access.
>>
>> In C# etc, you create separate dal classes and go with n-tier
>> architecture, should I just the validation, save, update in the controller
>> in pyramid or create separate classes.  Any help will be gratefully
>> appreciated.
>>
>
>
> My preference lately is to move all business and data logic to model methods
> and use views only to do views: ACL and context setup for template and
> response, a glue between involved models, templates, request data and
> response construction.

I generally put business logic in the model, but I may have a
different notion of business logic than Tanshu does. To me, business
logic is any calculations that are specific to the model but are
*independent* of the UI and HTML. So form validators belong in the
view, not the model. At most there might be a *generic* .__html__()
method on a model object to return its standard HTML representation.
But normally I put all HTML-related stuff in the templates or view.

If the business logic relates to a specific DB record, you can use an
ordinary method on the ORM class for it. But usually it relates to the
table; i.e., it returns a certain number of records. In that case it's
a class method on the ORM class (using @classmethod). Alternatively,
you can have a function in the model.

Some examples are in the Models chapter of the "Pyramid for Pylons
Users" guide in the Pyramid Cookbook.
http://docs.pylonsproject.org/projects/pyramid_cookbook/en/latest/pylons/models.html


-- 
Mike Orr <[email protected]>

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