My thoughts exactly, hence my confusion with the highlighted sentence. As
explained by Anthony in another reply, that sentence was let over from a
previous version of the doc. I like the idea of putting validators in the
model, assuming they are valid throughout the app (which makes sense).
Thanks again.
On Monday, July 23, 2012 1:58:26 PM UTC-6, Cliff Kachinske wrote:
>
> Caveat: my opinions. I am not a spokesperson for Web2py. That said:
>
> 1. No. MVC provides separation of functions as a way of organizing code.
> Usually programmers work together with designers, and MVC provides a way
> for them to interact without too much stepping on each other's toes.
> Typically a view would be concerned with css and other design aspects. To
> get some idea of what I mean, study the static/css files in your app. Also
> look at layout.html. MVC
>
> 2. You can put the validators anywhere in your code. It is convenient to
> put them in the model because that way you only have to do them once. Your
> validators would usually be the same across all controllers in your app, so
> why scatter them about?
>
> This situation is not something i 'live with.' It's a great convenience.
>
> On Monday, July 23, 2012 3:41:39 PM UTC-4, MichaelF wrote:
>>
>> The documentation says, in section 6.17.4 (my highlighting):
>>
>> 1 {{extend 'layout.html'}}
>>> 2 <h1>Records</h1>
>>> 3 {{=SQLTABLE(rows)}}
>>>
>>
>>
>> SQLTABLE converts the rows into an HTML table with a header containing the
>>> column names and one row per record. ...
>>
>> The values extracted from the database are also formatted by the
>>> validators
>>> associated to the field and then escaped. (Note: Using a db in this way
>>> in a
>>> view is usually not considered good MVC practice.)
>>
>>
>> I assume the doc means that validators shouldn't be used in a model file,
>> as the formatting that gets done as a result should be done by the view. Or
>> they should be used in a model file, but it's unfortunate that the
>> formatting gets done as a result, as opposed to being done in the view.
>>
>> 1. Is my assumption correct? If not, then why is this "not considered
>> good MVC practice"?
>>
>> 2. So what should be done in my web2py code, then? Add the validators in
>> the controller code? Or is this just something we live with as web2py
>> developers?
>>
>> Thanks.
>>
>
--