SQLFORM.factory creates a dummy DAL table via DAL(None). A change was made 
so that auto-validators no longer get applied to fields with DAL(None), so 
no fields in a SQLFORM.factory table will get the usual default DAL 
validators. Datetime fields typically get a default IS_DATETIME() validator 
(wrapped in IS_EMPTY_OR()), and that is what caused the conversion to a 
datetime object in the previous version of web2py. The IS_DATETIME() 
validator is no longer being added, so we no longer get the conversion.

This should be corrected somehow. I've posted on the developers list to get 
a discussion going: 
https://groups.google.com/forum/#!topic/web2py-developers/aX6CiPi4Dh0.

In the meantime, you can explicitly add the validator:

SQLFORM.factory(Field('startzeit', 'datetime', requires=IS_EMPTY_OR(
IS_DATETIME())))

Alternatively, you can do something like this:

def sqlform_factory(*fields, **attributes):
    from gluon.dal import _default_validators
    db = DAL(None)
    db.validators_method = lambda f: _default_validators(db, f)
    table = db.define_table('no_table', *fields)
    return SQLFORM.factory(*table, **attributes)

And then:

form = sqlform_factory(Field('startzeit', 'datetime'))

Anthony

On Monday, September 11, 2017 at 3:53:52 PM UTC-4, mweissen wrote:
>
> What is the type of the result of a Field(...;'datetime') ?
>
> I think, it should be "datetime" (and I am shure it has been in version 
> 2.14.x), but web2py 2.15.4 delivers a "str".
>
> def dttest2():
>     form = SQLFORM.factory(Field('startzeit', 'datetime'))
>     if form.process().accepted:
>         return \
>           str(isinstance(form.vars.startzeit,datetime.datetime))
>     return dict(form=form)
>
>
> The result is "False"
>
> ​Regards Martin​
>
>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to