You cannot use default=Expression('CURRENT_DATE',db=db) I.e. have the
default date inserted by the database and, at the same time, validate
the field at the web2py level (before) the record is communicated by
the database.  The field has to be writable=readable=False if you want
to use it in forms.

On Aug 28, 3:14 pm, Adrian Klaver <[email protected]> wrote:
> On Saturday 28 August 2010 7:51:59 am Kevin wrote:
>
> > I think what you are looking for is the Field's compute argument.
> > Check out compute and update arguments for the field constructor,
> > compared to what the default argument does.
>
> No not really. I wanted what Dr. DiPierro came up with, a way of passing a
> database variable (CURRENT_DATE) to the DEFAULT clause of the field. This lets
> the database do the work and reduces the duplication of effort on the client
> side.
>
>
>
> > I would get confused by this as well -- web2py does it the best way
> > and does it consistently, but when getting into I might have expected
> > default to do some magic based on whether the argument were callable
> > or not.
>
> Let me say I am impressed with Web2py and it has allowed to go further faster
> then any other framework I have looked at. In this particular case though I
> think I ran across a split personality problem. To illustrate in Field() you
> have a length argument that puts a length constraint at the database level i.e
> the actual field definition (CHAR(10)). At the form level you also have
> IS_LENGTH which is used by SQLFORM to perform basically the same function. The
> default argument however performs both duties and that presents a bit of a
> problem. In fact I spoke too soon earlier about the fix working. The fix
> allowed me to properly set the DEFAULT clause, but SQLFORM is having problems
> understanding what to do with the Expression.  See here:
>
> Traceback (most recent call last):
>   File "/home/aklaver/software_projects/w2py/web2py/gluon/restricted.py", line
> 188, in restricted
>     exec ccode in environment
>
> File 
> "/home/aklaver/software_projects/w2py/web2py/applications/hplc/controllers/appadmin.py",
> line 410, in <module>
>   File "/home/aklaver/software_projects/w2py/web2py/gluon/globals.py", line 
> 96,
> in <lambda>
>     self._caller = lambda f: f()
>
> File 
> "/home/aklaver/software_projects/w2py/web2py/applications/hplc/controllers/appadmin.py",
> line 124, in insert
>     form = SQLFORM(db[table], ignore_rw=ignore_rw)
>   File "/home/aklaver/software_projects/w2py/web2py/gluon/sqlhtml.py", line 
> 694,
> in __init__
>     default = field.formatter(default)
>   File "/home/aklaver/software_projects/w2py/web2py/gluon/sql.py", line 2869, 
> in
> formatter
>     value = item.formatter(value)
>   File "/home/aklaver/software_projects/w2py/web2py/gluon/validators.py", line
> 2023, in formatter
>     year = value.year
> AttributeError: 'Expression' object has no attribute 'year'
>
>
>
> > So perhaps this should go in the FAQ.
>
> --
> Adrian Klaver
> [email protected]

Reply via email to