Skip to content

Commit 5798c56

Browse files
author
Richard Jones
committed
allow specification of pagesize, sorting and filtering in "classhelp" popups
[SF#1211800]
1 parent 35ec49a commit 5798c56

File tree

3 files changed

+79
-14
lines changed

3 files changed

+79
-14
lines changed

CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ Fixed:
2222
- have 'roundup-admin security' display property restrictions (sf bug
2323
1222135)
2424
- fixed templating menu() sort_on handling (sf bug 1221936)
25+
- allow specification of pagesize, sorting and filtering in "classhelp"
26+
popups (sf bug 1211800)
2527

2628

2729
2005-05-02 0.8.3

doc/customizing.txt

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Customising Roundup
33
===================
44

5-
:Version: $Revision: 1.181 $
5+
:Version: $Revision: 1.182 $
66

77
.. This document borrows from the ZopeBook section on ZPT. The original is at:
88
http://www.zope.org/Documentation/Books/ZopeBook/current/ZPT.stx
@@ -1764,6 +1764,32 @@ filter lists of items from this class, filtered and sorted. Two
17641764

17651765
classhelp display a link to a javascript popup containing this class'
17661766
"help" template.
1767+
1768+
This generates a link to a popup window which displays the
1769+
properties indicated by "properties" of the class named by
1770+
"classname". The "properties" should be a comma-separated list
1771+
(eg. 'id,name,description'). Properties defaults to all the
1772+
properties of a class (excluding id, creator, created and
1773+
activity).
1774+
1775+
You may optionally override the "label" displayed, the "width",
1776+
the "height", the number of items per page ("pagesize") and
1777+
the field on which the list is sorted ("sort").
1778+
1779+
With the "filter" arg it is possible to specify a filter for
1780+
which items are supposed to be displayed. It has to be of
1781+
the format "<field>=<values>;<field>=<values>;...".
1782+
1783+
The popup window will be resizable and scrollable.
1784+
1785+
If the "property" arg is given, it's passed through to the
1786+
javascript help_window function. This allows updating of a
1787+
property in the calling HTML page.
1788+
1789+
If the "form" arg is given, it's passed through to the
1790+
javascript help_window function - it's the name of the form
1791+
the "property" belongs to.
1792+
17671793
submit generate a submit button (and action hidden element)
17681794
renderWith render this class with the given template.
17691795
history returns 'New node - no history' :)
@@ -1953,7 +1979,9 @@ menu only on Link and Multilink properties - render a form select
19531979
lists properties which should be included in the label
19541980
sort_on
19551981
indicates the property to sort the list on as (direction,
1956-
property) where direction is '+' or '-'.
1982+
(direction, property) where direction is '+' or '-'. A
1983+
single string with the direction prepended may be used.
1984+
For example: ('-', 'order'), '+name'.
19571985

19581986
The remaining keyword arguments are used as conditions for
19591987
filtering the items in the list - they're passed as the

roundup/cgi/templating.py

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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 = '&amp;@sort=username'
660+
else:
661+
sort = ''
662+
else:
663+
sort = '&amp;@sort=' + sort
648664
if property:
649665
property = '&amp;property=%s'%property
650666
if form:
651667
form = '&amp;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('&amp;%s=%s' % (name, urllib.quote(values)))
676+
filter = '&amp;@filter=%s%s' % (','.join(names), ''.join(filtervalues))
677+
else:
678+
filter = ''
652679
help_url = "%s?@startwith=0&amp;@template=help&amp;"\
653-
"properties=%s%s%s" % \
654-
(self.classname, properties, property, form)
680+
"properties=%s%s%s%s&amp;@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

Comments
 (0)