Changes between Initial Version and Version 1 of AlphaSort


Ignore:
Timestamp:
01/17/10 10:59:55 (15 years ago)
Author:
Fran Boon
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • AlphaSort

    v1 v1  
     1== AlphaSort ==
     2
     3Want to be able to sort a Dropdown alphabetically to make it easier for data entry
     4e.g. the Organisations dropdown in 'Add Office'
     5
     6We have 2 sorts of dropdowns:
     7 * Database
     8 * Dictionary
     9
     10This one is a Database one using the IS_ONE_OF() custom validator from {{{modules/validators.pty}}}
     11
     12js list sorter:
     13 * http://stackoverflow.com/questions/278089/javascript-to-sort-contents-of-select-element/278509#278509
     14
     15As far as sorting right in the backend is concerned - models/05_or.py line 107, tried putting .select(orderby = db.or_organsation.name)[0]...
     16But that did not work out...
     17
     18Q: If its possible to put a javascript fix where does one put a page specific js ?[[BR]]
     19A: {{{views/module/resource_method.html}}}
     20
     21For Dictionary-based ones:
     22{{{
     23In  models/05_or.py change:
     24
     25or_organisation_type_opts = {
     26   1:T('Government'),
     27   2:T('International Governmental Organization'),
     28   3:T('International NGO'),
     29   4:T('Misc'),
     30   5:T('National Institution'),
     31   6:T('National NGO'),
     32   7:T('United Nations')
     33   }
     34...
     35db[table].type.requires = IS_NULL_OR(IS_IN_SET(or_organisation_type_opts))
     36
     37into
     38
     39or_organisation_type_opts = [
     40   (1,T('Government')),
     41   (2,T('International Governmental Organization')),
     42   (3,T('International NGO')),
     43   (4,T('Misc')),
     44   (5,T('National Institution')),
     45   (6,T('National NGO')),
     46   (7,T('United Nations'))
     47]
     48...
     49db[table].type.requires = IS_NULL_OR(IS_IN_SET(
     50   [x[0] for x in or_organisation_type_opts],
     51   [x[1] for x in or_organisation_type_opts]))
     52}}}