Skip to content

Commit 1c48136

Browse files
author
Richard Jones
committed
bugfix to (multi)link menu() label generation
1 parent a8e117d commit 1c48136

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ are given with the most recent entry first.
1616
backends
1717
- we now verify instance attributes on instance open and throw a useful error
1818
if they're not all there
19+
- sf 611217 ] menu() has problems when labelprop==None
1920

2021

2122
2002-09-13 0.5.0 beta2

roundup/cgi/templating.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -930,16 +930,25 @@ def field(self, showid=0, size=None):
930930
s = ''
931931
l.append(_('<option %svalue="-1">- no selection -</option>')%s)
932932
for optionid in options:
933-
option = linkcl.get(optionid, k)
933+
# get the option value, and if it's None use an empty string
934+
option = linkcl.get(optionid, k) or ''
935+
936+
# figure if this option is selected
934937
s = ''
935938
if optionid == self._value:
936939
s = 'selected '
940+
941+
# figure the label
937942
if showid:
938943
lab = '%s%s: %s'%(self._prop.classname, optionid, option)
939944
else:
940945
lab = option
946+
947+
# truncate if it's too long
941948
if size is not None and len(lab) > size:
942949
lab = lab[:size-3] + '...'
950+
951+
# and generate
943952
lab = cgi.escape(lab)
944953
l.append('<option %svalue="%s">%s</option>'%(s, optionid, lab))
945954
l.append('</select>')
@@ -967,21 +976,30 @@ def menu(self, size=None, height=None, showid=0, additional=[],
967976
sort_on = ('+', linkcl.labelprop())
968977
options = linkcl.filter(None, conditions, sort_on, (None, None))
969978
for optionid in options:
970-
option = linkcl.get(optionid, k)
979+
# get the option value, and if it's None use an empty string
980+
option = linkcl.get(optionid, k) or ''
981+
982+
# figure if this option is selected
971983
s = ''
972984
if value in [optionid, option]:
973985
s = 'selected '
986+
987+
# figure the label
974988
if showid:
975989
lab = '%s%s: %s'%(self._prop.classname, optionid, option)
976990
else:
977991
lab = option
992+
993+
# truncate if it's too long
978994
if size is not None and len(lab) > size:
979995
lab = lab[:size-3] + '...'
980996
if additional:
981997
m = []
982998
for propname in additional:
983999
m.append(linkcl.get(optionid, propname))
9841000
lab = lab + ' (%s)'%', '.join(map(str, m))
1001+
1002+
# and generate
9851003
lab = cgi.escape(lab)
9861004
l.append('<option %svalue="%s">%s</option>'%(s, optionid, lab))
9871005
l.append('</select>')
@@ -1078,21 +1096,29 @@ def menu(self, size=None, height=None, showid=0, additional=[],
10781096
l = ['<select multiple name="%s" size="%s">'%(self._name, height)]
10791097
k = linkcl.labelprop(1)
10801098
for optionid in options:
1081-
option = linkcl.get(optionid, k)
1099+
# get the option value, and if it's None use an empty string
1100+
option = linkcl.get(optionid, k) or ''
1101+
1102+
# figure if this option is selected
10821103
s = ''
10831104
if optionid in value or option in value:
10841105
s = 'selected '
1106+
1107+
# figure the label
10851108
if showid:
10861109
lab = '%s%s: %s'%(self._prop.classname, optionid, option)
10871110
else:
10881111
lab = option
1112+
# truncate if it's too long
10891113
if size is not None and len(lab) > size:
10901114
lab = lab[:size-3] + '...'
10911115
if additional:
10921116
m = []
10931117
for propname in additional:
10941118
m.append(linkcl.get(optionid, propname))
10951119
lab = lab + ' (%s)'%', '.join(m)
1120+
1121+
# and generate
10961122
lab = cgi.escape(lab)
10971123
l.append('<option %svalue="%s">%s</option>'%(s, optionid,
10981124
lab))
@@ -1299,7 +1325,6 @@ def __str__(self):
12991325
d['env'] = e
13001326
return '''
13011327
form: %(form)s
1302-
url: %(url)r
13031328
base: %(base)r
13041329
classname: %(classname)r
13051330
template: %(template)r

0 commit comments

Comments
 (0)