Skip to content

Commit 49812ac

Browse files
author
Richard Jones
committed
Fixed handling of passed-in values in form elements (ie. during a drill-down)
1 parent 1e412a0 commit 49812ac

File tree

3 files changed

+65
-48
lines changed

3 files changed

+65
-48
lines changed

roundup/cgi_client.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: cgi_client.py,v 1.7 2001-07-29 07:01:39 richard Exp $
1+
# $Id: cgi_client.py,v 1.8 2001-07-29 08:27:40 richard Exp $
22

33
import os, cgi, pprint, StringIO, urlparse, re, traceback
44

@@ -105,22 +105,29 @@ def index_arg(self, arg):
105105

106106
def index_filterspec(self):
107107
''' pull the index filter spec from the form
108+
109+
Links and multilinks want to be lists - the rest are straight
110+
strings.
108111
'''
109-
# all the other form args are filters
112+
props = self.db.classes[self.classname].getprops()
113+
# all the form args not starting with ':' are filters
110114
filterspec = {}
111115
for key in self.form.keys():
112116
if key[0] == ':': continue
117+
prop = props[key]
113118
value = self.form[key]
114-
if type(value) == type([]):
115-
value = [arg.value for arg in value]
119+
if prop.isLinkType or prop.isMultilinkType:
120+
if type(value) == type([]):
121+
value = [arg.value for arg in value]
122+
else:
123+
value = value.value.split(',')
124+
l = filterspec.get(key, [])
125+
l = l + value
126+
filterspec[key] = l
116127
else:
117-
value = value.value.split(',')
118-
l = filterspec.get(key, [])
119-
l = l + value
120-
filterspec[key] = l
128+
filterspec[key] = value.value
121129
return filterspec
122130

123-
124131
default_index_sort = ['-activity']
125132
default_index_group = ['priority']
126133
default_index_filter = []
@@ -496,6 +503,9 @@ def __del__(self):
496503

497504
#
498505
# $Log: not supported by cvs2svn $
506+
# Revision 1.7 2001/07/29 07:01:39 richard
507+
# Added vim command to all source so that we don't get no steenkin' tabs :)
508+
#
499509
# Revision 1.6 2001/07/29 04:04:00 richard
500510
# Moved some code around allowing for subclassing to change behaviour.
501511
#

roundup/htmltemplate.py

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
# $Id: htmltemplate.py,v 1.8 2001-07-29 07:01:39 richard Exp $
1+
# $Id: htmltemplate.py,v 1.9 2001-07-29 08:27:40 richard Exp $
22

33
import os, re, StringIO, urllib, cgi, errno
44

55
import hyperdb, date
66

77
class Base:
8-
def __init__(self, db, templates, classname, nodeid=None, form=None):
8+
def __init__(self, db, templates, classname, nodeid=None, form=None,
9+
filterspec=None):
910
# TODO: really not happy with the way templates is passed on here
1011
self.db, self.templates = db, templates
1112
self.classname, self.nodeid = classname, nodeid
12-
self.form = form
13+
self.form, self.filterspec = form, filterspec
1314
self.cl = self.db.classes[self.classname]
1415
self.properties = self.cl.getprops()
1516

@@ -57,11 +58,16 @@ class Field(Base):
5758
to be edited
5859
'''
5960
def __call__(self, property, size=None, height=None, showid=0):
60-
if not self.nodeid and self.form is None:
61+
if not self.nodeid and self.form and self.filterspec is None:
6162
return '[Field: not called from item]'
6263
propclass = self.properties[property]
6364
if self.nodeid:
6465
value = self.cl.get(self.nodeid, property)
66+
elif self.filterspec is not None:
67+
if propclass.isMultilinkType:
68+
value = self.filterspec.get(property, [])
69+
else:
70+
value = self.filterspec.get(property, '')
6571
else:
6672
# TODO: pull the value from the form
6773
if propclass.isMultilinkType: value = []
@@ -265,6 +271,8 @@ def __call__(self, property, **args):
265271
propclass = self.properties[property]
266272
if self.nodeid:
267273
value = self.cl.get(self.nodeid, property)
274+
elif self.filterspec is not None:
275+
value = self.filterspec.get(property, [])
268276
else:
269277
value = []
270278
if propclass.isLinkType or propclass.isMultilinkType:
@@ -273,7 +281,7 @@ def __call__(self, property, **args):
273281
k = linkcl.labelprop()
274282
for optionid in linkcl.list():
275283
option = linkcl.get(optionid, k)
276-
if optionid in value:
284+
if optionid in value or option in value:
277285
checked = 'checked'
278286
else:
279287
checked = ''
@@ -405,22 +413,23 @@ def index(client, templates, db, classname, filterspec={}, filter=[],
405413
columns=[], sort=[], group=[], show_display_form=1, nodeids=None,
406414
col_re=re.compile(r'<property\s+name="([^>]+)">')):
407415
globals = {
408-
'plain': Plain(db, templates, classname, form={}),
409-
'field': Field(db, templates, classname, form={}),
410-
'menu': Menu(db, templates, classname, form={}),
411-
'link': Link(db, templates, classname, form={}),
412-
'count': Count(db, templates, classname, form={}),
413-
'reldate': Reldate(db, templates, classname, form={}),
414-
'download': Download(db, templates, classname, form={}),
415-
'checklist': Checklist(db, templates, classname, form={}),
416-
'list': List(db, templates, classname, form={}),
417-
'history': History(db, templates, classname, form={}),
418-
'submit': Submit(db, templates, classname, form={}),
419-
'note': Note(db, templates, classname, form={})
416+
'plain': Plain(db, templates, classname, filterspec=filterspec),
417+
'field': Field(db, templates, classname, filterspec=filterspec),
418+
'menu': Menu(db, templates, classname, filterspec=filterspec),
419+
'link': Link(db, templates, classname, filterspec=filterspec),
420+
'count': Count(db, templates, classname, filterspec=filterspec),
421+
'reldate': Reldate(db, templates, classname, filterspec=filterspec),
422+
'download': Download(db, templates, classname, filterspec=filterspec),
423+
'checklist': Checklist(db, templates, classname, filterspec=filterspec),
424+
'list': List(db, templates, classname, filterspec=filterspec),
425+
'history': History(db, templates, classname, filterspec=filterspec),
426+
'submit': Submit(db, templates, classname, filterspec=filterspec),
427+
'note': Note(db, templates, classname, filterspec=filterspec)
420428
}
421429
cl = db.classes[classname]
422430
properties = cl.getprops()
423431
w = client.write
432+
w('<form>')
424433

425434
try:
426435
template = open(os.path.join(templates, classname+'.filter')).read()
@@ -431,28 +440,26 @@ def index(client, templates, db, classname, filterspec={}, filter=[],
431440
all_filters = []
432441
if template and filter:
433442
# display the filter section
434-
w('<form>')
435443
w('<table width=100% border=0 cellspacing=0 cellpadding=2>')
436444
w('<tr class="location-bar">')
437445
w(' <th align="left" colspan="2">Filter specification...</th>')
438446
w('</tr>')
439447
replace = IndexTemplateReplace(globals, locals(), filter)
440448
w(replace.go(template))
441-
if columns:
442-
w('<input type="hidden" name=":columns" value="%s">'%','.join(columns))
443-
if filter:
444-
w('<input type="hidden" name=":filter" value="%s">'%','.join(filter))
445-
if sort:
446-
w('<input type="hidden" name=":sort" value="%s">'%','.join(sort))
447-
if group:
448-
w('<input type="hidden" name=":group" value="%s">'%','.join(group))
449-
for k, v in filterspec.items():
450-
if type(v) == type([]): v = ','.join(v)
451-
w('<input type="hidden" name="%s" value="%s">'%(k, v))
452449
w('<tr class="location-bar"><td width="1%%">&nbsp;</td>')
453450
w('<td><input type="submit" value="Redisplay"></td></tr>')
454451
w('</table>')
455-
w('</form>')
452+
453+
# If the filters aren't being displayed, then hide their current
454+
# value in the form
455+
if not filter:
456+
for k, v in filterspec.items():
457+
if type(v) == type([]): v = ','.join(v)
458+
w('<input type="hidden" name="%s" value="%s">'%(k, v))
459+
460+
# make sure that the sorting doesn't get lost either
461+
if sort:
462+
w('<input type="hidden" name=":sort" value="%s">'%','.join(sort))
456463

457464
# XXX deviate from spec here ...
458465
# load the index section template and figure the default columns from it
@@ -540,13 +547,8 @@ def index(client, templates, db, classname, filterspec={}, filter=[],
540547
return
541548

542549
# now add in the filter/columns/group/etc config table form
543-
w('<p><form>')
550+
w('<p>')
544551
w('<table width=100% border=0 cellspacing=0 cellpadding=2>')
545-
for k,v in filterspec.items():
546-
if type(v) == type([]): v = ','.join(v)
547-
w('<input type="hidden" name="%s" value="%s">'%(k, v))
548-
if sort:
549-
w('<input type="hidden" name=":sort" value="%s">'%','.join(sort))
550552
names = []
551553
for name in cl.getprops().keys():
552554
if name in all_filters or name in all_columns:
@@ -707,6 +709,9 @@ def newitem(client, templates, db, classname, form, replace=re.compile(
707709

708710
#
709711
# $Log: not supported by cvs2svn $
712+
# Revision 1.8 2001/07/29 07:01:39 richard
713+
# Added vim command to all source so that we don't get no steenkin' tabs :)
714+
#
710715
# Revision 1.7 2001/07/29 05:36:14 richard
711716
# Cleanup of the link label generation.
712717
#

roundup/hyperdb.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: hyperdb.py,v 1.7 2001-07-29 07:01:39 richard Exp $
1+
# $Id: hyperdb.py,v 1.8 2001-07-29 08:27:40 richard Exp $
22

33
# standard python modules
44
import cPickle, re, string
@@ -387,7 +387,7 @@ def getkey(self):
387387
"""Return the name of the key property for this class or None."""
388388
return self.key
389389

390-
def labelprop(self, nodeid):
390+
def labelprop(self):
391391
''' Return the property name for a label for the given node.
392392
393393
This method attempts to generate a consistent label for the node.
@@ -551,7 +551,6 @@ def filter(self, filterspec, sort, group, num_re = re.compile('^\d+$')):
551551
u.append(entry)
552552
l.append((1, k, u))
553553
elif propclass.isStringType:
554-
v = v[0]
555554
if '*' in v or '?' in v:
556555
# simple glob searching
557556
v = v.replace('?', '.')
@@ -789,6 +788,9 @@ def Choice(name, *options):
789788

790789
#
791790
# $Log: not supported by cvs2svn $
791+
# Revision 1.7 2001/07/29 07:01:39 richard
792+
# Added vim command to all source so that we don't get no steenkin' tabs :)
793+
#
792794
# Revision 1.6 2001/07/29 05:36:14 richard
793795
# Cleanup of the link label generation.
794796
#

0 commit comments

Comments
 (0)