When I have some time maybe I will do more experiments.
With sort=True I was (earlier) not sucessful. Because I think I need a 
lambda to set the order, boolean is not enough.
Inside options() I had (earlier) the set_trace point but I wasn't 
successful to stop the execution there. Not sure if it is called in form 
preparing/rendering.



On Friday, 10 February 2017 18:48:04 UTC+1, Anthony wrote:
>
> Does IS_IN_DB(sort=True) not do what you want? If not, it might be a bit 
> simpler to instead override the options() method of IS_IN_DB and just 
> provide an alternative function in place of options_sorter() (or, if you 
> want an alternative options_sorter in all cases, you could just monkey 
> patch it in gluon.validators).
>
> Anthony
>
> On Friday, February 10, 2017 at 12:08:58 PM UTC-5, Mirek Zvolský wrote:
>>
>> ... or to any other special order.
>>
>> For me was creazy that I was not able to sort items (names) in IS_IN_DB 
>> lists alphabetically.
>> IS_IN_DB has lot of undocumented parameters but I think nothing can help.
>>
>> Of course when running from Postgres, you will receive records with 
>> proper locale order.
>> However with SQLite you need (maybe) a hacked and special compiled SQLite 
>> to have correct order.
>> Otherwise you start with uppercase ascii, then follow lowercase ascii, 
>> and at the end are accented (non-ascii) characters. Crazy.
>>
>> Now I use this hack in my model:
>>
>> import locale
>> locale.setlocale(locale.LC_ALL, 'cs_CZ.UTF-8')
>>
>>
>> class IS_IN_DB_(IS_IN_DB):
>>     def build_set(self):
>>         super(IS_IN_DB_, self).build_set()
>>         records = [(lbl, self.theset[pos]) for pos, lbl in enumerate(self
>> .labels)]
>>         records.sort(key=lambda x: locale.strxfrm(x[0]))
>>         self.labels = [rec[0] for rec in records]
>>         self.theset = [rec[1] for rec in records]
>>
>>
>> db.define_table('payment',
>>     Field('idauth_user', 'reference auth_user', requires=IS_EMPTY_OR(
>> IS_IN_DB_(db, db.auth_user.id, '%(nick)s'))),
>>     ...)
>>
>>
>>
>> Not optimal, but works !
>>
>>

-- 
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