Skip to content

Commit b6731c6

Browse files
author
Richard Jones
committed
query "editing" now working, minus filling the form in with the query params
1 parent 868bb38 commit b6731c6

File tree

2 files changed

+40
-30
lines changed

2 files changed

+40
-30
lines changed

roundup/cgi/templating.py

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -360,13 +360,8 @@ def renderWith(self, name, **kwargs):
360360
# new template, using the specified classname and request
361361
pt = getTemplate(self._db.config.TEMPLATES, self.classname, name)
362362

363-
# XXX handle PT rendering errors here nicely
364-
try:
365-
# use our fabricated request
366-
return pt.render(self._client, self.classname, req)
367-
except PageTemplate.PTRuntimeError, message:
368-
return '<strong>%s</strong><ol>%s</ol>'%(message,
369-
cgi.escape('<li>'.join(pt._v_errors)))
363+
# use our fabricated request
364+
return pt.render(self._client, self.classname, req)
370365

371366
class HTMLItem:
372367
''' Accesses through an *item*
@@ -568,6 +563,20 @@ def history(self, direction='descending'):
568563
l.append('</table>')
569564
return '\n'.join(l)
570565

566+
def renderQueryForm(self):
567+
''' Render this item, which is a query, as a search form.
568+
'''
569+
# create a new request and override the specified args
570+
req = HTMLRequest(self._client)
571+
req.classname = self._klass.get(self._nodeid, 'klass')
572+
req.updateFromURL(self._klass.get(self._nodeid, 'url'))
573+
574+
# new template, using the specified classname and request
575+
pt = getTemplate(self._db.config.TEMPLATES, req.classname, 'search')
576+
577+
# use our fabricated request
578+
return pt.render(self._client, req.classname, req)
579+
571580
class HTMLUser(HTMLItem):
572581
''' Accesses through the *user* (a special case of item)
573582
'''
@@ -1035,6 +1044,11 @@ def __init__(self, client):
10351044
self.classname = client.classname
10361045
self.template = client.template
10371046

1047+
self._post_init()
1048+
1049+
def _post_init(self):
1050+
''' Set attributes based on self.form
1051+
'''
10381052
# extract the index display information from the form
10391053
self.columns = []
10401054
if self.form.has_key(':columns'):
@@ -1096,7 +1110,25 @@ def __init__(self, client):
10961110
else:
10971111
self.startwith = 0
10981112

1113+
def updateFromURL(self, url):
1114+
''' Parse the URL for query args, and update my attributes using the
1115+
values.
1116+
'''
1117+
self.form = {}
1118+
for name, value in cgi.parse_qsl(url):
1119+
if self.form.has_key(name):
1120+
if isinstance(self.form[name], type([])):
1121+
self.form[name].append(cgi.MiniFieldStorage(name, value))
1122+
else:
1123+
self.form[name] = [self.form[name],
1124+
cgi.MiniFieldStorage(name, value)]
1125+
else:
1126+
self.form[name] = cgi.MiniFieldStorage(name, value)
1127+
self._post_init()
1128+
10991129
def update(self, kwargs):
1130+
''' Update my attributes using the keyword args
1131+
'''
11001132
self.__dict__.update(kwargs)
11011133
if kwargs.has_key('columns'):
11021134
self.show = ShowDict(self.columns)
Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,2 @@
1-
<table class="form">
2-
<tr>
3-
<th>Class</th>
4-
<td tal:content="structure context/klass/field"></td>
5-
</tr>
6-
7-
<tr>
8-
<th>Name</th>
9-
<td tal:content="structure context/name/field"></td>
10-
</tr>
11-
12-
<tr>
13-
<td colspan=2>
14-
hrm. filterspec here...
15-
<display call="filterspec('klass','url')">
16-
</td>
17-
</tr>
18-
19-
<tr>
20-
<td>&nbsp;</td>
21-
<td tal:content="structure context/submit">submit button here</td>
22-
</tr>
23-
</table>
1+
<span tal:content="structure context/renderQueryForm" />
242

0 commit comments

Comments
 (0)