When creating extra fields for auth_user, the validation messages for those fields are always in English. They don't comply with the translations available.
This does not happen on the default fields.
I added this to db.py
auth.settings.extra_fields['auth_user'] = [Field('pagination', 'integer', default=9, label=T('Pagination'), notnull=True, required=True, requires=IS_INT_IN_RANGE(5, 51))]
When inserting an invalid value, the returned message is always
Enter an integer between 5 and 50
even when the web2py language is not English and the languages files have the correct translation available.
web2py 2.18.4
Python 3.7.1 x86
Firefox 66.0.2 x64
Windows 7 Pro x64 SP1+all updates
I have confirmed that it is indeed a bug in web2py.
If I add
T.force('pt')
auth.settings.extra_fields['auth_user'] = [ Field('pagination', 'integer', default=9, label=T('Pagination'), notnull=True, required=True, requires=IS_INT_IN_RANGE(5, 51), ), ]
the validation messages all come out in Portuguese (even if I change the language to English).
So the problem is that the code for the extra_fields is not language independent.
table = db.sn_counter # type: Table
grid = SQLFORM.grid(
table,
csv=False,
details=False,
ondelete=on_delete, # Grid only.
onvalidation=on_validation, # Form only.
orderby=db.sn_counter.name,
paginate=session.auth.user.pagination,
# represent_none='', # Grid and view form only.
sortable=False,
) # type: gluon.DIV
db.define_table('sn_counter',
Field('name', 'string', label=T('Name'), length=NAME_LEN, notnull=True,
required=True, unique=True),
Field('last_assigned', 'integer', default=0, label=T('Last assigned'),
notnull=True, required=True),
Field('canceled_on', 'datetime', label=T('Canceled on'), writable=False),
Field('canceled_by', 'reference auth_user', label=T('Canceled by'),
writable=False),
Field('cancel_approved_by', 'reference auth_user',
label=T('Cancel approved by'), writable=False),
auth.signature,
# common_filter = lambda query: db.sn_counter.is_active == True,
format='%(name)s',
# plural=T('sn counters'), singular=T('sn counter'),
)
# db.sn_counter.name.requires = (IS_NOT_EMPTY(), IS_NOT_IN_DB(db, 'sn_counter.name'))
db.sn_counter.last_assigned.requires = IS_INT_IN_RANGE(0, 100000)
Thanks Anthony. I will open an issue (I still haven't enough know how to make a PR). I hope some time in the future.I don't want to abuse your help, but I have another issue that is viewable with the minimal app I sent you.If you create 2 records with different dates, and try to change the grid's sort order you will notice that the URL changes, the page reloads but the grid doesn't change.I checked the db stats SQL statements and they stay the same (they don't change the ORDER).I think there is a bug with the sorting of date columns when they are the predefined orderby. Can you try it and give me your input.
def fix_orderby(orderby):
if not auto_pagination:
return orderby
# enforce always an ORDER clause to avoid
# pagination errors. field_id is needed anyhow,
# is unique and usually indexed. See issue #679
if not orderby:
orderby = field_id
elif isinstance(orderby, list):
orderby = reduce(lambda a,b: a|b, orderby)
elif isinstance(orderby, Field) and orderby is not field_id:
print('inside2')
# here we're with an ASC order on a field stored as orderby
orderby = orderby | field_id
elif (isinstance(orderby, Expression) and
orderby.first and orderby.first is not field_id):
print('inside3')
# here we're with a DESC order on a field stored as orderby.first
orderby = orderby | field_id
return orderby
exception = sort_field.type in ('date', 'datetime', 'time')
if exception:
desc_icon, asc_icon = sorter_icons
orderby = (order[:1] == '~' and sort_field) or ~sort_field
else:
orderby = (order[:1] == '~' and ~sort_field) or sort_field
exception = sort_field.type in ('date', 'datetime', 'time')
# if exception:
# desc_icon, asc_icon = sorter_icons
# orderby = (order[:1] == '~' and sort_field) or ~sort_field
#else:
orderby = (order[:1] == '~' and ~sort_field) or sort_field