Mercurial > p > roundup > code
changeset 128:ce36f2962b94
Fixed handling of passed-in values in form elements (ie. during a drill-down)
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Sun, 29 Jul 2001 08:27:40 +0000 |
| parents | 0791d13baea7 |
| children | 614bbffe063c |
| files | roundup/cgi_client.py roundup/htmltemplate.py roundup/hyperdb.py |
| diffstat | 3 files changed, 65 insertions(+), 48 deletions(-) [+] |
line wrap: on
line diff
--- a/roundup/cgi_client.py Sun Jul 29 07:01:39 2001 +0000 +++ b/roundup/cgi_client.py Sun Jul 29 08:27:40 2001 +0000 @@ -1,4 +1,4 @@ -# $Id: cgi_client.py,v 1.7 2001-07-29 07:01:39 richard Exp $ +# $Id: cgi_client.py,v 1.8 2001-07-29 08:27:40 richard Exp $ import os, cgi, pprint, StringIO, urlparse, re, traceback @@ -105,22 +105,29 @@ def index_filterspec(self): ''' pull the index filter spec from the form + + Links and multilinks want to be lists - the rest are straight + strings. ''' - # all the other form args are filters + props = self.db.classes[self.classname].getprops() + # all the form args not starting with ':' are filters filterspec = {} for key in self.form.keys(): if key[0] == ':': continue + prop = props[key] value = self.form[key] - if type(value) == type([]): - value = [arg.value for arg in value] + if prop.isLinkType or prop.isMultilinkType: + if type(value) == type([]): + value = [arg.value for arg in value] + else: + value = value.value.split(',') + l = filterspec.get(key, []) + l = l + value + filterspec[key] = l else: - value = value.value.split(',') - l = filterspec.get(key, []) - l = l + value - filterspec[key] = l + filterspec[key] = value.value return filterspec - default_index_sort = ['-activity'] default_index_group = ['priority'] default_index_filter = [] @@ -496,6 +503,9 @@ # # $Log: not supported by cvs2svn $ +# Revision 1.7 2001/07/29 07:01:39 richard +# Added vim command to all source so that we don't get no steenkin' tabs :) +# # Revision 1.6 2001/07/29 04:04:00 richard # Moved some code around allowing for subclassing to change behaviour. #
--- a/roundup/htmltemplate.py Sun Jul 29 07:01:39 2001 +0000 +++ b/roundup/htmltemplate.py Sun Jul 29 08:27:40 2001 +0000 @@ -1,15 +1,16 @@ -# $Id: htmltemplate.py,v 1.8 2001-07-29 07:01:39 richard Exp $ +# $Id: htmltemplate.py,v 1.9 2001-07-29 08:27:40 richard Exp $ import os, re, StringIO, urllib, cgi, errno import hyperdb, date class Base: - def __init__(self, db, templates, classname, nodeid=None, form=None): + def __init__(self, db, templates, classname, nodeid=None, form=None, + filterspec=None): # TODO: really not happy with the way templates is passed on here self.db, self.templates = db, templates self.classname, self.nodeid = classname, nodeid - self.form = form + self.form, self.filterspec = form, filterspec self.cl = self.db.classes[self.classname] self.properties = self.cl.getprops() @@ -57,11 +58,16 @@ to be edited ''' def __call__(self, property, size=None, height=None, showid=0): - if not self.nodeid and self.form is None: + if not self.nodeid and self.form and self.filterspec is None: return '[Field: not called from item]' propclass = self.properties[property] if self.nodeid: value = self.cl.get(self.nodeid, property) + elif self.filterspec is not None: + if propclass.isMultilinkType: + value = self.filterspec.get(property, []) + else: + value = self.filterspec.get(property, '') else: # TODO: pull the value from the form if propclass.isMultilinkType: value = [] @@ -265,6 +271,8 @@ propclass = self.properties[property] if self.nodeid: value = self.cl.get(self.nodeid, property) + elif self.filterspec is not None: + value = self.filterspec.get(property, []) else: value = [] if propclass.isLinkType or propclass.isMultilinkType: @@ -273,7 +281,7 @@ k = linkcl.labelprop() for optionid in linkcl.list(): option = linkcl.get(optionid, k) - if optionid in value: + if optionid in value or option in value: checked = 'checked' else: checked = '' @@ -405,22 +413,23 @@ columns=[], sort=[], group=[], show_display_form=1, nodeids=None, col_re=re.compile(r'<property\s+name="([^>]+)">')): globals = { - 'plain': Plain(db, templates, classname, form={}), - 'field': Field(db, templates, classname, form={}), - 'menu': Menu(db, templates, classname, form={}), - 'link': Link(db, templates, classname, form={}), - 'count': Count(db, templates, classname, form={}), - 'reldate': Reldate(db, templates, classname, form={}), - 'download': Download(db, templates, classname, form={}), - 'checklist': Checklist(db, templates, classname, form={}), - 'list': List(db, templates, classname, form={}), - 'history': History(db, templates, classname, form={}), - 'submit': Submit(db, templates, classname, form={}), - 'note': Note(db, templates, classname, form={}) + 'plain': Plain(db, templates, classname, filterspec=filterspec), + 'field': Field(db, templates, classname, filterspec=filterspec), + 'menu': Menu(db, templates, classname, filterspec=filterspec), + 'link': Link(db, templates, classname, filterspec=filterspec), + 'count': Count(db, templates, classname, filterspec=filterspec), + 'reldate': Reldate(db, templates, classname, filterspec=filterspec), + 'download': Download(db, templates, classname, filterspec=filterspec), + 'checklist': Checklist(db, templates, classname, filterspec=filterspec), + 'list': List(db, templates, classname, filterspec=filterspec), + 'history': History(db, templates, classname, filterspec=filterspec), + 'submit': Submit(db, templates, classname, filterspec=filterspec), + 'note': Note(db, templates, classname, filterspec=filterspec) } cl = db.classes[classname] properties = cl.getprops() w = client.write + w('<form>') try: template = open(os.path.join(templates, classname+'.filter')).read() @@ -431,28 +440,26 @@ all_filters = [] if template and filter: # display the filter section - w('<form>') w('<table width=100% border=0 cellspacing=0 cellpadding=2>') w('<tr class="location-bar">') w(' <th align="left" colspan="2">Filter specification...</th>') w('</tr>') replace = IndexTemplateReplace(globals, locals(), filter) w(replace.go(template)) - if columns: - w('<input type="hidden" name=":columns" value="%s">'%','.join(columns)) - if filter: - w('<input type="hidden" name=":filter" value="%s">'%','.join(filter)) - if sort: - w('<input type="hidden" name=":sort" value="%s">'%','.join(sort)) - if group: - w('<input type="hidden" name=":group" value="%s">'%','.join(group)) + w('<tr class="location-bar"><td width="1%%"> </td>') + w('<td><input type="submit" value="Redisplay"></td></tr>') + w('</table>') + + # If the filters aren't being displayed, then hide their current + # value in the form + if not filter: for k, v in filterspec.items(): if type(v) == type([]): v = ','.join(v) w('<input type="hidden" name="%s" value="%s">'%(k, v)) - w('<tr class="location-bar"><td width="1%%"> </td>') - w('<td><input type="submit" value="Redisplay"></td></tr>') - w('</table>') - w('</form>') + + # make sure that the sorting doesn't get lost either + if sort: + w('<input type="hidden" name=":sort" value="%s">'%','.join(sort)) # XXX deviate from spec here ... # load the index section template and figure the default columns from it @@ -540,13 +547,8 @@ return # now add in the filter/columns/group/etc config table form - w('<p><form>') + w('<p>') w('<table width=100% border=0 cellspacing=0 cellpadding=2>') - for k,v in filterspec.items(): - if type(v) == type([]): v = ','.join(v) - w('<input type="hidden" name="%s" value="%s">'%(k, v)) - if sort: - w('<input type="hidden" name=":sort" value="%s">'%','.join(sort)) names = [] for name in cl.getprops().keys(): if name in all_filters or name in all_columns: @@ -707,6 +709,9 @@ # # $Log: not supported by cvs2svn $ +# Revision 1.8 2001/07/29 07:01:39 richard +# Added vim command to all source so that we don't get no steenkin' tabs :) +# # Revision 1.7 2001/07/29 05:36:14 richard # Cleanup of the link label generation. #
--- a/roundup/hyperdb.py Sun Jul 29 07:01:39 2001 +0000 +++ b/roundup/hyperdb.py Sun Jul 29 08:27:40 2001 +0000 @@ -1,4 +1,4 @@ -# $Id: hyperdb.py,v 1.7 2001-07-29 07:01:39 richard Exp $ +# $Id: hyperdb.py,v 1.8 2001-07-29 08:27:40 richard Exp $ # standard python modules import cPickle, re, string @@ -387,7 +387,7 @@ """Return the name of the key property for this class or None.""" return self.key - def labelprop(self, nodeid): + def labelprop(self): ''' Return the property name for a label for the given node. This method attempts to generate a consistent label for the node. @@ -551,7 +551,6 @@ u.append(entry) l.append((1, k, u)) elif propclass.isStringType: - v = v[0] if '*' in v or '?' in v: # simple glob searching v = v.replace('?', '.') @@ -789,6 +788,9 @@ # # $Log: not supported by cvs2svn $ +# Revision 1.7 2001/07/29 07:01:39 richard +# Added vim command to all source so that we don't get no steenkin' tabs :) +# # Revision 1.6 2001/07/29 05:36:14 richard # Cleanup of the link label generation. #
