Logically -- without much web2py familiarity -- I would think that the
constraints specified in the model would be be applied absolutely
anywhere the model is used.  So when you have a constraint like in the
example model:

  db.purchases.quantity.requires=IS_INT_IN_RANGE(0,10)

The model would prevent any integer outside of that range (0-9
inclusive) from being added into the quantity field regardless of
constraints specified in custom forms.

So the following custom form specific constraint:

 
TR("Quantity:",INPUT(_type="text",_name="quantity",requires=IS_INT_IN_RANGE
(1,100))),

would only further limit the constraint specified by the model.  If
this were the case, it wouldn't make sense to allow values in the
custom form that the model did not allow.  For instance, a value of 50
would pass the custom form validation, but get rejected by the model
constraint.  So the custom form constraint would effectively limit the
values to 1-9 inclusive (10-99 would get rejected by the model
constraint).

I usually consider model definitions as hard rules for the data that
should not be broken.  But as Massimo stated, this is not the way it
is implemented.  It is too easy to be a critic when you aren't the one
doing the implementation.

Keep up the great work!

On Mar 23, 12:39 pm, villas <villa...@gmail.com> wrote:
> If I undertood correctly,  you expect the model to have priority over
> any other validation constraints.
>
> This is not how it works in web2py.  You may override validations at
> any point and my experience is that it is very useful to do so.
>
> If you wish to enforce a DB constraint which could not be overridden,
> I suppose you might consider doing that in the DB itself.
>
> On Mar 23, 3:45 pm, Jaunx <dale.notting...@gmail.com> wrote:
>
>
>
>
>
>
>
> > In Example 29 of the "Database Examples" of the Quick Examples
> > tutorial, the last line of the model definition file (db.py) puts the
> > following constraint on the purchases.quantity field:
>
> >   db.purchases.quantity.requires=IS_INT_IN_RANGE(0,10)
>
> > In Example 33, the controller for the purchase form (forth line of the
> > buy method in database_examples.py) defines the following constraint
> > on the quantity:
>
> > TR("Quantity:",INPUT(_type="text",_name="quantity",requires=IS_INT_IN_RANGE 
> > (1,100))),
>
> > When you actually test the example application, the form accepts
> > values between 1 and 99 inclusive and the database is updated with the
> > appropriate value.
>
> > What is the point of the constraint in the model definition if it is
> > not enforced?  Seems like the model would be the ideal place to set
> > this constraint so that it doesn't need to be repeated for every form
> > that uses it.  However it would be nice to be able to override the
> > default per form if necessary.

Reply via email to