Mercurial > p > roundup > code
comparison roundup/cgi/client.py @ 1631:8a908bbad1ef
A couple of form value handling changes:
- multilink properties may hhave multiple form values "1", "2,4", "5", ...
- string search properties are split on whitespace and match any of the
values
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Fri, 09 May 2003 01:47:51 +0000 |
| parents | e109d59f232d |
| children | e5e00d3a3fe2 |
comparison
equal
deleted
inserted
replaced
| 1629:27768800be5c | 1631:8a908bbad1ef |
|---|---|
| 1 # $Id: client.py,v 1.114 2003-04-24 07:19:59 richard Exp $ | 1 # $Id: client.py,v 1.115 2003-05-09 01:47:50 richard Exp $ |
| 2 | 2 |
| 3 __doc__ = """ | 3 __doc__ = """ |
| 4 WWW request handler (also used in the stand-alone server). | 4 WWW request handler (also used in the stand-alone server). |
| 5 """ | 5 """ |
| 6 | 6 |
| 1281 if not self.db.security.hasPermission('Edit', self.userid, | 1281 if not self.db.security.hasPermission('Edit', self.userid, |
| 1282 self.classname): | 1282 self.classname): |
| 1283 return 0 | 1283 return 0 |
| 1284 return 1 | 1284 return 1 |
| 1285 | 1285 |
| 1286 def searchAction(self): | 1286 def searchAction(self, wcre=re.compile(r'[\s,]+')): |
| 1287 ''' Mangle some of the form variables. | 1287 ''' Mangle some of the form variables. |
| 1288 | 1288 |
| 1289 Set the form ":filter" variable based on the values of the | 1289 Set the form ":filter" variable based on the values of the |
| 1290 filter variables - if they're set to anything other than | 1290 filter variables - if they're set to anything other than |
| 1291 "dontcare" then add them to :filter. | 1291 "dontcare" then add them to :filter. |
| 1292 | 1292 |
| 1293 Also handle the ":queryname" variable and save off the query to | 1293 Handle the ":queryname" variable and save off the query to |
| 1294 the user's query list. | 1294 the user's query list. |
| 1295 | |
| 1296 Split any String query values on whitespace and comma. | |
| 1295 ''' | 1297 ''' |
| 1296 # generic edit is per-class only | 1298 # generic edit is per-class only |
| 1297 if not self.searchPermission(): | 1299 if not self.searchPermission(): |
| 1298 self.error_message.append( | 1300 self.error_message.append( |
| 1299 _('You do not have permission to search %s' %self.classname)) | 1301 _('You do not have permission to search %s' %self.classname)) |
| 1317 else: | 1319 else: |
| 1318 continue | 1320 continue |
| 1319 else: | 1321 else: |
| 1320 if not self.form[key].value: | 1322 if not self.form[key].value: |
| 1321 continue | 1323 continue |
| 1324 if isinstance(props[key], hyperdb.String): | |
| 1325 v = self.form[key].value | |
| 1326 l = wcre.split(v) | |
| 1327 if len(l) > 1: | |
| 1328 self.form.value.remove(self.form[key]) | |
| 1329 # replace the single value with the split list | |
| 1330 for v in l: | |
| 1331 self.form.value.append(cgi.MiniFieldStorage(key, v)) | |
| 1332 | |
| 1322 self.form.value.append(cgi.MiniFieldStorage('@filter', key)) | 1333 self.form.value.append(cgi.MiniFieldStorage('@filter', key)) |
| 1323 | 1334 |
| 1324 # handle saving the query params | 1335 # handle saving the query params |
| 1325 if queryname: | 1336 if queryname: |
| 1326 # parse the environment and figure what the query _is_ | 1337 # parse the environment and figure what the query _is_ |
| 1855 | 1866 |
| 1856 def extractFormList(value): | 1867 def extractFormList(value): |
| 1857 ''' Extract a list of values from the form value. | 1868 ''' Extract a list of values from the form value. |
| 1858 | 1869 |
| 1859 It may be one of: | 1870 It may be one of: |
| 1860 [MiniFieldStorage, MiniFieldStorage, ...] | 1871 [MiniFieldStorage('value'), MiniFieldStorage('value','value',...), ...] |
| 1861 MiniFieldStorage('value,value,...') | 1872 MiniFieldStorage('value,value,...') |
| 1862 MiniFieldStorage('value') | 1873 MiniFieldStorage('value') |
| 1863 ''' | 1874 ''' |
| 1864 # multiple values are OK | 1875 # multiple values are OK |
| 1865 if isinstance(value, type([])): | 1876 if isinstance(value, type([])): |
| 1866 # it's a list of MiniFieldStorages | 1877 # it's a list of MiniFieldStorages - join then into |
| 1867 value = [i.value.strip() for i in value] | 1878 values = ','.join([i.value.strip() for i in value]) |
| 1868 else: | 1879 else: |
| 1869 # it's a MiniFieldStorage, but may be a comma-separated list | 1880 # it's a MiniFieldStorage, but may be a comma-separated list |
| 1870 # of values | 1881 # of values |
| 1871 value = [i.strip() for i in value.value.split(',')] | 1882 values = value.value |
| 1883 | |
| 1884 value = [i.strip() for i in values.split(',')] | |
| 1872 | 1885 |
| 1873 # filter out the empty bits | 1886 # filter out the empty bits |
| 1874 return filter(None, value) | 1887 return filter(None, value) |
| 1875 | 1888 |
