@@ -621,7 +621,8 @@ def filter(self, request=None, filterspec={}, sort=(None,None),
621621 return l
622622
623623 def classhelp (self , properties = None , label = '' "(list)" , width = '500' ,
624- height = '400' , property = '' , form = 'itemSynopsis' ):
624+ height = '400' , property = '' , form = 'itemSynopsis' ,
625+ pagesize = 50 , sort = None , filter = None ):
625626 '''Pop up a javascript window with class help
626627
627628 This generates a link to a popup window which displays the
@@ -631,8 +632,16 @@ def classhelp(self, properties=None, label=''"(list)", width='500',
631632 properties of a class (excluding id, creator, created and
632633 activity).
633634
634- You may optionally override the label displayed, the width and
635- height. The popup window will be resizable and scrollable.
635+ You may optionally override the label displayed, the width,
636+ the height, the number of items per page and the field on which
637+ the list is sorted (defaults to username if in the displayed
638+ properties).
639+
640+ With the "filter" arg it is possible to specify a filter for
641+ which items are supposed to be displayed. It has to be of
642+ the format "<field>=<values>;<field>=<values>;...".
643+
644+ The popup window will be resizable and scrollable.
636645
637646 If the "property" arg is given, it's passed through to the
638647 javascript help_window function.
@@ -645,13 +654,31 @@ def classhelp(self, properties=None, label=''"(list)", width='500',
645654 properties = self ._klass .getprops (protected = 0 ).keys ()
646655 properties .sort ()
647656 properties = ',' .join (properties )
657+ if sort is None :
658+ if 'username' in properties .split ( ',' ):
659+ sort = '&@sort=username'
660+ else :
661+ sort = ''
662+ else :
663+ sort = '&@sort=' + sort
648664 if property :
649665 property = '&property=%s' % property
650666 if form :
651667 form = '&form=%s' % form
668+ if filter :
669+ filterprops = filter .split (';' )
670+ filtervalues = []
671+ names = []
672+ for x in filterprops :
673+ (name , values ) = x .split ('=' )
674+ names .append (name )
675+ filtervalues .append ('&%s=%s' % (name , urllib .quote (values )))
676+ filter = '&@filter=%s%s' % (',' .join (names ), '' .join (filtervalues ))
677+ else :
678+ filter = ''
652679 help_url = "%s?@startwith=0&@template=help&" \
653- "properties=%s%s%s" % \
654- (self .classname , properties , property , form )
680+ "properties=%s%s%s%s&@pagesize=%s%s " % \
681+ (self .classname , properties , property , form , sort , pagesize , filter )
655682 onclick = "javascript:help_window('%s', '%s', '%s');return false;" % \
656683 (help_url , width , height )
657684 return '<a class="classhelp" href="%s" onclick="%s">%s</a>' % \
@@ -1659,16 +1686,16 @@ def menu(self, size=None, height=None, showid=0, additional=[],
16591686 if value is None :
16601687 s = 'selected="selected" '
16611688 l .append (self ._ ('<option %svalue="-1">- no selection -</option>' )% s )
1689+
16621690 if sort_on is not None :
16631691 if not isinstance (sort_on , tuple ):
16641692 if sort_on [0 ] in '+-' :
16651693 sort_on = (sort_on [0 ], sort_on [1 :])
16661694 else :
16671695 sort_on = ('+' , sort_on )
1668- elif linkcl .getprops ().has_key ('order' ):
1669- sort_on = ('+' , 'order' )
16701696 else :
1671- sort_on = ('+' , linkcl .labelprop ())
1697+ sort_on = ('+' , find_sort_key (linkcl ))
1698+
16721699 options = linkcl .filter (None , conditions , sort_on , (None , None ))
16731700
16741701 # make sure we list the current value if it's retired
@@ -1821,7 +1848,9 @@ def menu(self, size=None, height=None, showid=0, additional=[],
18211848 "additional" lists properties which should be included in the
18221849 label
18231850 "sort_on" indicates the property to sort the list on as
1824- (direction, property) where direction is '+' or '-'.
1851+ (direction, property) where direction is '+' or '-'. A
1852+ single string with the direction prepended may be used.
1853+ For example: ('-', 'order'), '+name'.
18251854
18261855 The remaining keyword arguments are used as conditions for
18271856 filtering the items in the list - they're passed as the
@@ -1835,10 +1864,16 @@ def menu(self, size=None, height=None, showid=0, additional=[],
18351864 value = self ._value
18361865
18371866 linkcl = self ._db .getclass (self ._prop .classname )
1838- if sort_on is None :
1839- sort_on = ('+' , find_sort_key (linkcl ))
1867+
1868+ if sort_on is not None :
1869+ if not isinstance (sort_on , tuple ):
1870+ if sort_on [0 ] in '+-' :
1871+ sort_on = (sort_on [0 ], sort_on [1 :])
1872+ else :
1873+ sort_on = ('+' , sort_on )
18401874 else :
1841- sort_on = ('+' , sort_on )
1875+ sort_on = ('+' , find_sort_key (linkcl ))
1876+
18421877 options = linkcl .filter (None , conditions , sort_on )
18431878 height = height or min (len (options ), 7 )
18441879 l = ['<select multiple name="%s" size="%s">' % (self ._formname , height )]
0 commit comments