@@ -620,7 +620,8 @@ def filter(self, request=None, filterspec={}, sort=(None,None),
620620 return l
621621
622622 def classhelp (self , properties = None , label = '' "(list)" , width = '500' ,
623- height = '400' , property = '' , form = 'itemSynopsis' ):
623+ height = '400' , property = '' , form = 'itemSynopsis' ,
624+ pagesize = 50 , sort = None , filter = None ):
624625 '''Pop up a javascript window with class help
625626
626627 This generates a link to a popup window which displays the
@@ -630,8 +631,16 @@ def classhelp(self, properties=None, label=''"(list)", width='500',
630631 properties of a class (excluding id, creator, created and
631632 activity).
632633
633- You may optionally override the label displayed, the width and
634- height. The popup window will be resizable and scrollable.
634+ You may optionally override the label displayed, the width,
635+ the height, the number of items per page and the field on which
636+ the list is sorted (defaults to username if in the displayed
637+ properties).
638+
639+ With the "filter" arg it is possible to specify a filter for
640+ which items are supposed to be displayed. It has to be of
641+ the format "<field>=<values>;<field>=<values>;...".
642+
643+ The popup window will be resizable and scrollable.
635644
636645 If the "property" arg is given, it's passed through to the
637646 javascript help_window function.
@@ -644,13 +653,31 @@ def classhelp(self, properties=None, label=''"(list)", width='500',
644653 properties = self ._klass .getprops (protected = 0 ).keys ()
645654 properties .sort ()
646655 properties = ',' .join (properties )
656+ if sort is None :
657+ if 'username' in properties .split ( ',' ):
658+ sort = '&@sort=username'
659+ else :
660+ sort = ''
661+ else :
662+ sort = '&@sort=' + sort
647663 if property :
648664 property = '&property=%s' % property
649665 if form :
650666 form = '&form=%s' % form
667+ if filter :
668+ filterprops = filter .split (';' )
669+ filtervalues = []
670+ names = []
671+ for x in filterprops :
672+ (name , values ) = x .split ('=' )
673+ names .append (name )
674+ filtervalues .append ('&%s=%s' % (name , urllib .quote (values )))
675+ filter = '&@filter=%s%s' % (',' .join (names ), '' .join (filtervalues ))
676+ else :
677+ filter = ''
651678 help_url = "%s?@startwith=0&@template=help&" \
652- "properties=%s%s%s" % \
653- (self .classname , properties , property , form )
679+ "properties=%s%s%s%s&@pagesize=%s%s " % \
680+ (self .classname , properties , property , form , sort , pagesize , filter )
654681 onclick = "javascript:help_window('%s', '%s', '%s');return false;" % \
655682 (help_url , width , height )
656683 return '<a class="classhelp" href="%s" onclick="%s">%s</a>' % \
@@ -1643,16 +1670,16 @@ def menu(self, size=None, height=None, showid=0, additional=[],
16431670 if value is None :
16441671 s = 'selected="selected" '
16451672 l .append (self ._ ('<option %svalue="-1">- no selection -</option>' )% s )
1673+
16461674 if sort_on is not None :
16471675 if not isinstance (sort_on , tuple ):
16481676 if sort_on [0 ] in '+-' :
16491677 sort_on = (sort_on [0 ], sort_on [1 :])
16501678 else :
16511679 sort_on = ('+' , sort_on )
1652- elif linkcl .getprops ().has_key ('order' ):
1653- sort_on = ('+' , 'order' )
16541680 else :
1655- sort_on = ('+' , linkcl .labelprop ())
1681+ sort_on = ('+' , find_sort_key (linkcl ))
1682+
16561683 options = linkcl .filter (None , conditions , sort_on , (None , None ))
16571684
16581685 # make sure we list the current value if it's retired
@@ -1805,7 +1832,9 @@ def menu(self, size=None, height=None, showid=0, additional=[],
18051832 "additional" lists properties which should be included in the
18061833 label
18071834 "sort_on" indicates the property to sort the list on as
1808- (direction, property) where direction is '+' or '-'.
1835+ (direction, property) where direction is '+' or '-'. A
1836+ single string with the direction prepended may be used.
1837+ For example: ('-', 'order'), '+name'.
18091838
18101839 The remaining keyword arguments are used as conditions for
18111840 filtering the items in the list - they're passed as the
@@ -1819,10 +1848,16 @@ def menu(self, size=None, height=None, showid=0, additional=[],
18191848 value = self ._value
18201849
18211850 linkcl = self ._db .getclass (self ._prop .classname )
1822- if sort_on is None :
1823- sort_on = ('+' , find_sort_key (linkcl ))
1851+
1852+ if sort_on is not None :
1853+ if not isinstance (sort_on , tuple ):
1854+ if sort_on [0 ] in '+-' :
1855+ sort_on = (sort_on [0 ], sort_on [1 :])
1856+ else :
1857+ sort_on = ('+' , sort_on )
18241858 else :
1825- sort_on = ('+' , sort_on )
1859+ sort_on = ('+' , find_sort_key (linkcl ))
1860+
18261861 options = linkcl .filter (None , conditions , sort_on )
18271862 height = height or min (len (options ), 7 )
18281863 l = ['<select multiple name="%s" size="%s">' % (self ._formname , height )]
0 commit comments