Mercurial > p > roundup > code
comparison roundup/cgi/templating.py @ 3860:c672b15ddae6
- fix id-lookup in case we already *know* that the value is an id (in
case of a multilink property for example)
| author | Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net> |
|---|---|
| date | Thu, 05 Jul 2007 21:11:28 +0000 |
| parents | 54c10d188b8b |
| children | d4ac8954ce5c |
comparison
equal
deleted
inserted
replaced
| 3859:9e48fda4a41c | 3860:c672b15ddae6 |
|---|---|
| 360 m = [] | 360 m = [] |
| 361 for item in l: | 361 for item in l: |
| 362 m.append(HTMLClass(self._client, item)) | 362 m.append(HTMLClass(self._client, item)) |
| 363 return m | 363 return m |
| 364 | 364 |
| 365 def lookupIds(db, prop, ids, fail_ok=0, num_re=re.compile('^-?\d+$')): | 365 num_re = re.compile('^-?\d+$') |
| 366 | |
| 367 def lookupIds(db, prop, ids, fail_ok=0, num_re=num_re, do_lookup=True): | |
| 366 """ "fail_ok" should be specified if we wish to pass through bad values | 368 """ "fail_ok" should be specified if we wish to pass through bad values |
| 367 (most likely form values that we wish to represent back to the user) | 369 (most likely form values that we wish to represent back to the user) |
| 370 "do_lookup" is there for preventing lookup by key-value (if we | |
| 371 know that the value passed *is* an id) | |
| 368 """ | 372 """ |
| 369 cl = db.getclass(prop.classname) | 373 cl = db.getclass(prop.classname) |
| 370 l = [] | 374 l = [] |
| 371 for entry in ids: | 375 for entry in ids: |
| 372 try: | 376 try: |
| 373 l.append(cl.lookup(entry)) | 377 if do_lookup: |
| 378 l.append(cl.lookup(entry)) | |
| 379 continue | |
| 374 except (TypeError, KeyError): | 380 except (TypeError, KeyError): |
| 375 # if fail_ok, ignore lookup error | 381 pass |
| 376 # otherwise entry must be existing object id rather than key value | 382 # if fail_ok, ignore lookup error |
| 377 if fail_ok or num_re.match(entry): | 383 # otherwise entry must be existing object id rather than key value |
| 378 l.append(entry) | 384 if fail_ok or num_re.match(entry): |
| 385 l.append(entry) | |
| 379 return l | 386 return l |
| 380 | 387 |
| 381 def lookupKeys(linkcl, key, ids, num_re=re.compile('^-?\d+$')): | 388 def lookupKeys(linkcl, key, ids, num_re=num_re): |
| 382 """ Look up the "key" values for "ids" list - though some may already | 389 """ Look up the "key" values for "ids" list - though some may already |
| 383 be key values, not ids. | 390 be key values, not ids. |
| 384 """ | 391 """ |
| 385 l = [] | 392 l = [] |
| 386 for entry in ids: | 393 for entry in ids: |
| 550 | 557 |
| 551 def designator(self): | 558 def designator(self): |
| 552 """ Return this class' designator (classname) """ | 559 """ Return this class' designator (classname) """ |
| 553 return self._classname | 560 return self._classname |
| 554 | 561 |
| 555 def getItem(self, itemid, num_re=re.compile('^-?\d+$')): | 562 def getItem(self, itemid, num_re=num_re): |
| 556 """ Get an item of this class by its item id. | 563 """ Get an item of this class by its item id. |
| 557 """ | 564 """ |
| 558 # make sure we're looking at an itemid | 565 # make sure we're looking at an itemid |
| 559 if not isinstance(itemid, type(1)) and not num_re.match(itemid): | 566 if not isinstance(itemid, type(1)) and not num_re.match(itemid): |
| 560 itemid = self._klass.lookup(itemid) | 567 itemid = self._klass.lookup(itemid) |
| 1868 """ | 1875 """ |
| 1869 def __init__(self, *args, **kwargs): | 1876 def __init__(self, *args, **kwargs): |
| 1870 HTMLProperty.__init__(self, *args, **kwargs) | 1877 HTMLProperty.__init__(self, *args, **kwargs) |
| 1871 if self._value: | 1878 if self._value: |
| 1872 display_value = lookupIds(self._db, self._prop, self._value, | 1879 display_value = lookupIds(self._db, self._prop, self._value, |
| 1873 fail_ok=1) | 1880 fail_ok=1, do_lookup=False) |
| 1874 sortfun = make_sort_function(self._db, self._prop.classname) | 1881 sortfun = make_sort_function(self._db, self._prop.classname) |
| 1875 # sorting fails if the value contains | 1882 # sorting fails if the value contains |
| 1876 # items not yet stored in the database | 1883 # items not yet stored in the database |
| 1877 # ignore these errors to preserve user input | 1884 # ignore these errors to preserve user input |
| 1878 try: | 1885 try: |
