Skip to content

Commit 71dffcd

Browse files
author
Richard Jones
committed
added sorting of checklist HTML display
1 parent 2f3dd09 commit 71dffcd

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

roundup/htmltemplate.py

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: htmltemplate.py,v 1.97 2002-07-09 05:20:09 richard Exp $
18+
# $Id: htmltemplate.py,v 1.98 2002-07-10 00:17:46 richard Exp $
1919

2020
__doc__ = """
2121
Template engine.
@@ -480,9 +480,11 @@ def do_download(self, property, **args):
480480
return self.do_link(property, is_download=1)
481481

482482

483-
def do_checklist(self, property, **args):
483+
def do_checklist(self, property, sortby=None):
484484
''' for a Link or Multilink property, display checkboxes for the
485485
available choices to permit filtering
486+
487+
sort the checklist by the argument (+/- property name)
486488
'''
487489
propclass = self.properties[property]
488490
if (not isinstance(propclass, hyperdb.Link) and not
@@ -507,8 +509,32 @@ def do_checklist(self, property, **args):
507509
linkcl = self.db.classes[propclass.classname]
508510
l = []
509511
k = linkcl.labelprop(1)
512+
513+
# build list of options and then sort it, either
514+
# by id + label or <sortby>-value + label;
515+
# a minus reverses the sort order, while + or no
516+
# prefix sort in increasing order
517+
reversed = 0
518+
if sortby:
519+
if sortby[0] == '-':
520+
reversed = 1
521+
sortby = sortby[1:]
522+
elif sortby[0] == '+':
523+
sortby = sortby[1:]
524+
options = []
510525
for optionid in linkcl.list():
526+
if sortby:
527+
sortval = linkcl.get(optionid, sortby)
528+
else:
529+
sortval = int(optionid)
511530
option = cgi.escape(str(linkcl.get(optionid, k)))
531+
options.append((sortval, option, optionid))
532+
options.sort()
533+
if reversed:
534+
options.reverse()
535+
536+
# build checkboxes
537+
for sortval, option, optionid in options:
512538
if optionid in value or option in value:
513539
checked = 'checked'
514540
else:
@@ -742,8 +768,6 @@ def do_classhelp(self, classname, properties, label='?', width='400',
742768
return '<a href="javascript:help_window(\'classhelp?classname=%s&' \
743769
'properties=%s\', \'%s\', \'%s\')"><b>(%s)</b></a>'%(classname,
744770
properties, width, height, label)
745-
#return '<a href="classhelp?classname=%s&properties=%s" target="classhelp"><b>(%s)</b></a>'%(classname,
746-
# properties, label)
747771

748772
def do_email(self, property, escape=0):
749773
'''display the property as one or more "fudged" email addrs
@@ -1266,6 +1290,10 @@ def render(self, form):
12661290

12671291
#
12681292
# $Log: not supported by cvs2svn $
1293+
# Revision 1.97 2002/07/09 05:20:09 richard
1294+
# . added email display function - mangles email addrs so they're not so easily
1295+
# scraped from the web
1296+
#
12691297
# Revision 1.96 2002/07/09 04:19:09 richard
12701298
# Added reindex command to roundup-admin.
12711299
# Fixed reindex on first access.

0 commit comments

Comments
 (0)