comparison roundup/cgi/templating.py @ 1097:98f3d41f41d9

query "editing" now working, minus filling the form in with the query params
author Richard Jones <richard@users.sourceforge.net>
date Tue, 10 Sep 2002 03:57:50 +0000
parents fa7df238e2d4
children 7362dc1f0226
comparison
equal deleted inserted replaced
1096:fa7df238e2d4 1097:98f3d41f41d9
358 req.update(kwargs) 358 req.update(kwargs)
359 359
360 # new template, using the specified classname and request 360 # new template, using the specified classname and request
361 pt = getTemplate(self._db.config.TEMPLATES, self.classname, name) 361 pt = getTemplate(self._db.config.TEMPLATES, self.classname, name)
362 362
363 # XXX handle PT rendering errors here nicely 363 # use our fabricated request
364 try: 364 return pt.render(self._client, self.classname, req)
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)))
370 365
371 class HTMLItem: 366 class HTMLItem:
372 ''' Accesses through an *item* 367 ''' Accesses through an *item*
373 ''' 368 '''
374 def __init__(self, client, classname, nodeid): 369 def __init__(self, client, classname, nodeid):
566 for entry in comments.values(): 561 for entry in comments.values():
567 l.append('<tr><td colspan=4>%s</td></tr>'%entry) 562 l.append('<tr><td colspan=4>%s</td></tr>'%entry)
568 l.append('</table>') 563 l.append('</table>')
569 return '\n'.join(l) 564 return '\n'.join(l)
570 565
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
571 class HTMLUser(HTMLItem): 580 class HTMLUser(HTMLItem):
572 ''' Accesses through the *user* (a special case of item) 581 ''' Accesses through the *user* (a special case of item)
573 ''' 582 '''
574 def __init__(self, client, classname, nodeid): 583 def __init__(self, client, classname, nodeid):
575 HTMLItem.__init__(self, client, 'user', nodeid) 584 HTMLItem.__init__(self, client, 'user', nodeid)
1033 1042
1034 # store the current class name and action 1043 # store the current class name and action
1035 self.classname = client.classname 1044 self.classname = client.classname
1036 self.template = client.template 1045 self.template = client.template
1037 1046
1047 self._post_init()
1048
1049 def _post_init(self):
1050 ''' Set attributes based on self.form
1051 '''
1038 # extract the index display information from the form 1052 # extract the index display information from the form
1039 self.columns = [] 1053 self.columns = []
1040 if self.form.has_key(':columns'): 1054 if self.form.has_key(':columns'):
1041 self.columns = handleListCGIValue(self.form[':columns']) 1055 self.columns = handleListCGIValue(self.form[':columns'])
1042 self.show = ShowDict(self.columns) 1056 self.show = ShowDict(self.columns)
1094 if self.form.has_key(':startwith'): 1108 if self.form.has_key(':startwith'):
1095 self.startwith = int(self.form[':startwith'].value) 1109 self.startwith = int(self.form[':startwith'].value)
1096 else: 1110 else:
1097 self.startwith = 0 1111 self.startwith = 0
1098 1112
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
1099 def update(self, kwargs): 1129 def update(self, kwargs):
1130 ''' Update my attributes using the keyword args
1131 '''
1100 self.__dict__.update(kwargs) 1132 self.__dict__.update(kwargs)
1101 if kwargs.has_key('columns'): 1133 if kwargs.has_key('columns'):
1102 self.show = ShowDict(self.columns) 1134 self.show = ShowDict(self.columns)
1103 1135
1104 def description(self): 1136 def description(self):

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