On 06/06/2012 09:18 PM, Mike Orr wrote:
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



I'd argue that model data validation, which may be another way to call form validation, belongs to the model. For that I use colander which is then agnostic of the input method (form, XML, JSON API, ...). If the validator raises exceptions, then the view can handle them appropriately: construct warnings, mark invalid fields, etc... which then clearly belongs to the view and template. The same validators are then available to command line scripts that reuse the models, cron tasks, ..., and it is even nicely unit-testable.



--

.oO V Oo.

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