Mercurial > p > roundup > code
comparison roundup/cgi/templating.py @ 2049:5a5f66e6b0e1
forward-port of fix from maint-0-6
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Wed, 25 Feb 2004 09:40:46 +0000 |
| parents | 35ed1560ba2b |
| children | ba1d54edc53f |
comparison
equal
deleted
inserted
replaced
| 2046:f913b6beac35 | 2049:5a5f66e6b0e1 |
|---|---|
| 274 if item == 'user': | 274 if item == 'user': |
| 275 m.append(HTMLUserClass(self._client, item)) | 275 m.append(HTMLUserClass(self._client, item)) |
| 276 m.append(HTMLClass(self._client, item)) | 276 m.append(HTMLClass(self._client, item)) |
| 277 return r | 277 return r |
| 278 | 278 |
| 279 def lookupIds(db, prop, ids, num_re=re.compile('-?\d+')): | 279 def lookupIds(db, prop, ids, fail_ok=False, num_re=re.compile('-?\d+')): |
| 280 ''' "fail_ok" should be specified if we wish to pass through bad values | |
| 281 (most likely form values that we wish to represent back to the user) | |
| 282 ''' | |
| 280 cl = db.getclass(prop.classname) | 283 cl = db.getclass(prop.classname) |
| 281 l = [] | 284 l = [] |
| 282 for entry in ids: | 285 for entry in ids: |
| 283 if num_re.match(entry): | 286 if num_re.match(entry): |
| 284 l.append(entry) | 287 l.append(entry) |
| 285 else: | 288 else: |
| 286 try: | 289 try: |
| 287 l.append(cl.lookup(entry)) | 290 l.append(cl.lookup(entry)) |
| 288 except KeyError: | 291 except (TypeError, KeyError): |
| 289 # ignore invalid keys | 292 if fail_ok: |
| 290 pass | 293 # pass through the bad value |
| 294 l.append(entry) | |
| 291 return l | 295 return l |
| 292 | 296 |
| 293 class HTMLPermissions: | 297 class HTMLPermissions: |
| 294 ''' Helpers that provide answers to commonly asked Permission questions. | 298 ''' Helpers that provide answers to commonly asked Permission questions. |
| 295 ''' | 299 ''' |
| 380 if not isinstance(prop, klass): | 384 if not isinstance(prop, klass): |
| 381 continue | 385 continue |
| 382 if form.has_key(item): | 386 if form.has_key(item): |
| 383 if isinstance(prop, hyperdb.Multilink): | 387 if isinstance(prop, hyperdb.Multilink): |
| 384 value = lookupIds(self._db, prop, | 388 value = lookupIds(self._db, prop, |
| 385 handleListCGIValue(form[item])) | 389 handleListCGIValue(form[item]), fail_ok=True) |
| 386 elif isinstance(prop, hyperdb.Link): | 390 elif isinstance(prop, hyperdb.Link): |
| 387 value = form[item].value.strip() | 391 value = form[item].value.strip() |
| 388 if value: | 392 if value: |
| 389 value = lookupIds(self._db, prop, [value])[0] | 393 value = lookupIds(self._db, prop, [value], |
| 394 fail_ok=True)[0] | |
| 390 else: | 395 else: |
| 391 value = None | 396 value = None |
| 392 else: | 397 else: |
| 393 value = form[item].value.strip() or None | 398 value = form[item].value.strip() or None |
| 394 else: | 399 else: |
