Skip to content

Commit b274517

Browse files
author
Richard Jones
committed
Fixed Checklist function - wasn't always working on a list.
1 parent 2d156fe commit b274517

File tree

1 file changed

+30
-17
lines changed

1 file changed

+30
-17
lines changed

roundup/htmltemplate.py

Lines changed: 30 additions & 17 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.27 2001-10-20 12:13:44 richard Exp $
18+
# $Id: htmltemplate.py,v 1.28 2001-10-21 00:00:16 richard Exp $
1919

2020
import os, re, StringIO, urllib, cgi, errno
2121

@@ -305,27 +305,37 @@ class Checklist(Base):
305305
'''
306306
def __call__(self, property, **args):
307307
propclass = self.properties[property]
308+
if (not isinstance(propclass, hyperdb.Link) and not
309+
isinstance(propclass, hyperdb.Multilink)):
310+
return '[Checklist: not a link]'
311+
312+
# get our current checkbox state
308313
if self.nodeid:
309-
value = self.cl.get(self.nodeid, property)
314+
# get the info from the node - make sure it's a list
315+
if isinstance(propclass, hyperdb.Link:
316+
value = [self.cl.get(self.nodeid, property)]
317+
else:
318+
value = self.cl.get(self.nodeid, property)
310319
elif self.filterspec is not None:
320+
# get the state from the filter specification (always a list)
311321
value = self.filterspec.get(property, [])
312322
else:
323+
# it's a new node, so there's no state
313324
value = []
314-
if (isinstance(propclass, hyperdb.Link) or
315-
isinstance(propclass, hyperdb.Multilink)):
316-
linkcl = self.db.classes[propclass.classname]
317-
l = []
318-
k = linkcl.labelprop()
319-
for optionid in linkcl.list():
320-
option = linkcl.get(optionid, k)
321-
if optionid in value or option in value:
322-
checked = 'checked'
323-
else:
324-
checked = ''
325-
l.append('%s:<input type="checkbox" %s name="%s" value="%s">'%(
326-
option, checked, property, option))
327-
return '\n'.join(l)
328-
return '[Checklist: not a link]'
325+
326+
# so we can map to the linked node's "lable" property
327+
linkcl = self.db.classes[propclass.classname]
328+
l = []
329+
k = linkcl.labelprop()
330+
for optionid in linkcl.list():
331+
option = linkcl.get(optionid, k)
332+
if optionid in value or option in value:
333+
checked = 'checked'
334+
else:
335+
checked = ''
336+
l.append('%s:<input type="checkbox" %s name="%s" value="%s">'%(
337+
option, checked, property, option))
338+
return '\n'.join(l)
329339

330340
class Note(Base):
331341
''' display a "note" field, which is a text area for entering a note to
@@ -758,6 +768,9 @@ def newitem(client, templates, db, classname, form, replace=re.compile(
758768

759769
#
760770
# $Log: not supported by cvs2svn $
771+
# Revision 1.27 2001/10/20 12:13:44 richard
772+
# Fixed grouping of non-str properties (thanks Roch'e Compaan)
773+
#
761774
# Revision 1.26 2001/10/14 10:55:00 richard
762775
# Handle empty strings in HTML template Link function
763776
#

0 commit comments

Comments
 (0)