This one took me a while to figure it out:
im declaring a model as:
date_format = "%Y-%m-%d"
db.define_table("bookings"
, Field("start_date", "datetime")
, Field("end_date", "date", requires = IS_DATE(format=date_format))
, Field("agency", "reference agencies", format="{agency}")
, Field("name", "string", length=10)
, Field("people", "integer", default=0)
, Field("rooms", "integer", default=0)
, Field("price", "double", default=0.0)
)
def TextWidget(field, value):
return INPUT(_value = value, requires=field.requires, _name=field.name,
_class="form-control input-sm")
db.bookings.name.widget = TextWidget
db.bookings.end_date.widget = TextWidget
And a text widget to output the fields:
On my view i get the right iso representation but when i submit the form i
get this error:
My browser locale was set Spanish (es-ES).
The IS_DATE validator outputs the declared date format but tries to
validate with a translated one which is really weird way to process a form.
Also the translation of Year to "Año" is not something python would
recognize.
At the default es.py we can find:
Which is contributing to this error.
So the IS_DATE is doing something different to what was been told which is
to use the specified format regardless the accepted language.
The validators should not be translating anything unless they are told to.
It would be more versatile to pass the translated format to the validator
instead of doing this behind the scenes. Something like
IS_DATE(format=T(my_date_format))
validators.py, line 2235 IS_DATE
def __init__(self, format='%Y-%m-%d',
error_message='Enter date as %(format)s'):
self.format = translate(format)
For now ill modify the validators not to translate, but without patching
this, either you have to delete the related Spanish entries or maybe set
them the same as the English ones.
Thanks
Best Regards.
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.