comparison roundup/cgi/templating.py @ 1169:7b448a2425fd

bugfix to (multi)link menu() label generation
author Richard Jones <richard@users.sourceforge.net>
date Wed, 18 Sep 2002 22:26:07 +0000
parents cc67cc87cc9c
children af104fa52746
comparison
equal deleted inserted replaced
1168:94620e088e3a 1169:7b448a2425fd
928 s = 'selected ' 928 s = 'selected '
929 else: 929 else:
930 s = '' 930 s = ''
931 l.append(_('<option %svalue="-1">- no selection -</option>')%s) 931 l.append(_('<option %svalue="-1">- no selection -</option>')%s)
932 for optionid in options: 932 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
934 s = '' 937 s = ''
935 if optionid == self._value: 938 if optionid == self._value:
936 s = 'selected ' 939 s = 'selected '
940
941 # figure the label
937 if showid: 942 if showid:
938 lab = '%s%s: %s'%(self._prop.classname, optionid, option) 943 lab = '%s%s: %s'%(self._prop.classname, optionid, option)
939 else: 944 else:
940 lab = option 945 lab = option
946
947 # truncate if it's too long
941 if size is not None and len(lab) > size: 948 if size is not None and len(lab) > size:
942 lab = lab[:size-3] + '...' 949 lab = lab[:size-3] + '...'
950
951 # and generate
943 lab = cgi.escape(lab) 952 lab = cgi.escape(lab)
944 l.append('<option %svalue="%s">%s</option>'%(s, optionid, lab)) 953 l.append('<option %svalue="%s">%s</option>'%(s, optionid, lab))
945 l.append('</select>') 954 l.append('</select>')
946 return '\n'.join(l) 955 return '\n'.join(l)
947 956
965 sort_on = ('+', 'order') 974 sort_on = ('+', 'order')
966 else: 975 else:
967 sort_on = ('+', linkcl.labelprop()) 976 sort_on = ('+', linkcl.labelprop())
968 options = linkcl.filter(None, conditions, sort_on, (None, None)) 977 options = linkcl.filter(None, conditions, sort_on, (None, None))
969 for optionid in options: 978 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
971 s = '' 983 s = ''
972 if value in [optionid, option]: 984 if value in [optionid, option]:
973 s = 'selected ' 985 s = 'selected '
986
987 # figure the label
974 if showid: 988 if showid:
975 lab = '%s%s: %s'%(self._prop.classname, optionid, option) 989 lab = '%s%s: %s'%(self._prop.classname, optionid, option)
976 else: 990 else:
977 lab = option 991 lab = option
992
993 # truncate if it's too long
978 if size is not None and len(lab) > size: 994 if size is not None and len(lab) > size:
979 lab = lab[:size-3] + '...' 995 lab = lab[:size-3] + '...'
980 if additional: 996 if additional:
981 m = [] 997 m = []
982 for propname in additional: 998 for propname in additional:
983 m.append(linkcl.get(optionid, propname)) 999 m.append(linkcl.get(optionid, propname))
984 lab = lab + ' (%s)'%', '.join(map(str, m)) 1000 lab = lab + ' (%s)'%', '.join(map(str, m))
1001
1002 # and generate
985 lab = cgi.escape(lab) 1003 lab = cgi.escape(lab)
986 l.append('<option %svalue="%s">%s</option>'%(s, optionid, lab)) 1004 l.append('<option %svalue="%s">%s</option>'%(s, optionid, lab))
987 l.append('</select>') 1005 l.append('</select>')
988 return '\n'.join(l) 1006 return '\n'.join(l)
989 # def checklist(self, ...) 1007 # def checklist(self, ...)
1076 options = linkcl.filter(None, conditions, sort_on, (None,None)) 1094 options = linkcl.filter(None, conditions, sort_on, (None,None))
1077 height = height or min(len(options), 7) 1095 height = height or min(len(options), 7)
1078 l = ['<select multiple name="%s" size="%s">'%(self._name, height)] 1096 l = ['<select multiple name="%s" size="%s">'%(self._name, height)]
1079 k = linkcl.labelprop(1) 1097 k = linkcl.labelprop(1)
1080 for optionid in options: 1098 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
1082 s = '' 1103 s = ''
1083 if optionid in value or option in value: 1104 if optionid in value or option in value:
1084 s = 'selected ' 1105 s = 'selected '
1106
1107 # figure the label
1085 if showid: 1108 if showid:
1086 lab = '%s%s: %s'%(self._prop.classname, optionid, option) 1109 lab = '%s%s: %s'%(self._prop.classname, optionid, option)
1087 else: 1110 else:
1088 lab = option 1111 lab = option
1112 # truncate if it's too long
1089 if size is not None and len(lab) > size: 1113 if size is not None and len(lab) > size:
1090 lab = lab[:size-3] + '...' 1114 lab = lab[:size-3] + '...'
1091 if additional: 1115 if additional:
1092 m = [] 1116 m = []
1093 for propname in additional: 1117 for propname in additional:
1094 m.append(linkcl.get(optionid, propname)) 1118 m.append(linkcl.get(optionid, propname))
1095 lab = lab + ' (%s)'%', '.join(m) 1119 lab = lab + ' (%s)'%', '.join(m)
1120
1121 # and generate
1096 lab = cgi.escape(lab) 1122 lab = cgi.escape(lab)
1097 l.append('<option %svalue="%s">%s</option>'%(s, optionid, 1123 l.append('<option %svalue="%s">%s</option>'%(s, optionid,
1098 lab)) 1124 lab))
1099 l.append('</select>') 1125 l.append('</select>')
1100 return '\n'.join(l) 1126 return '\n'.join(l)
1297 for k,v in self.env.items(): 1323 for k,v in self.env.items():
1298 e += '\n %r=%r'%(k, v) 1324 e += '\n %r=%r'%(k, v)
1299 d['env'] = e 1325 d['env'] = e
1300 return ''' 1326 return '''
1301 form: %(form)s 1327 form: %(form)s
1302 url: %(url)r
1303 base: %(base)r 1328 base: %(base)r
1304 classname: %(classname)r 1329 classname: %(classname)r
1305 template: %(template)r 1330 template: %(template)r
1306 columns: %(columns)r 1331 columns: %(columns)r
1307 sort: %(sort)r 1332 sort: %(sort)r

Roundup Issue Tracker: http://roundup-tracker.org/