Prepolulate datetime field internationalization problem

24 views
Skip to first unread message

Sebastián Tromer

unread,
Apr 14, 2015, 6:39:01 PM4/14/15
to web...@googlegroups.com
Hello everyone!

I'm prepopulating a form made with the FORM helper.
In the form I have 2 INPUTs of type DATETIME:

INPUT(_name='from', _class='datetime', requires = IS_DATETIME())

I'm prepolutaing this field with:

form.vars.from = request.now

and I'm getting something like this: 2015-04-14 19:31:36.242654

this works OK if the locale is 'en' but when I have my browser with locale 'es'
the input should be prepopulated with the format '%d/%m/%Y %H:%M:%S.mmmmmm'
because web2py (somehow) knows that it must validate using 'es' locale.

So, the question is: How can I prepopulate a datetime input field that pass validation in any locale?

Thanks!

Massimo Di Pierro

unread,
Apr 15, 2015, 9:44:00 AM4/15/15
to web...@googlegroups.com
One solution is:

form.vars.from = IS_DATETIME()(request.now)[0]

Sebastián Tromer

unread,
Apr 15, 2015, 10:15:20 AM4/15/15
to web...@googlegroups.com
That didn't work, but looking at the code of appadmin and gluon/validators.py I found a possible solution:

form.vars.from = IS_DATETIME().formatter(request.now)

this is working OK.

Thanks Massimo!
Reply all
Reply to author
Forward
0 new messages