Skip to content

Commit 08a2b3d

Browse files
author
Ralf Schlatterbeck
committed
- fix id-lookup in case we already *know* that the value is an id (in
case of a multilink property for example)
1 parent 2e1f199 commit 08a2b3d

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

roundup/cgi/templating.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -362,23 +362,30 @@ def classes(self):
362362
m.append(HTMLClass(self._client, item))
363363
return m
364364

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):
366368
""" "fail_ok" should be specified if we wish to pass through bad values
367369
(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)
368372
"""
369373
cl = db.getclass(prop.classname)
370374
l = []
371375
for entry in ids:
372376
try:
373-
l.append(cl.lookup(entry))
377+
if do_lookup:
378+
l.append(cl.lookup(entry))
379+
continue
374380
except (TypeError, KeyError):
375-
# if fail_ok, ignore lookup error
376-
# otherwise entry must be existing object id rather than key value
377-
if fail_ok or num_re.match(entry):
378-
l.append(entry)
381+
pass
382+
# if fail_ok, ignore lookup error
383+
# otherwise entry must be existing object id rather than key value
384+
if fail_ok or num_re.match(entry):
385+
l.append(entry)
379386
return l
380387

381-
def lookupKeys(linkcl, key, ids, num_re=re.compile('^-?\d+$')):
388+
def lookupKeys(linkcl, key, ids, num_re=num_re):
382389
""" Look up the "key" values for "ids" list - though some may already
383390
be key values, not ids.
384391
"""
@@ -552,7 +559,7 @@ def designator(self):
552559
""" Return this class' designator (classname) """
553560
return self._classname
554561

555-
def getItem(self, itemid, num_re=re.compile('^-?\d+$')):
562+
def getItem(self, itemid, num_re=num_re):
556563
""" Get an item of this class by its item id.
557564
"""
558565
# make sure we're looking at an itemid
@@ -1870,7 +1877,7 @@ def __init__(self, *args, **kwargs):
18701877
HTMLProperty.__init__(self, *args, **kwargs)
18711878
if self._value:
18721879
display_value = lookupIds(self._db, self._prop, self._value,
1873-
fail_ok=1)
1880+
fail_ok=1, do_lookup=False)
18741881
sortfun = make_sort_function(self._db, self._prop.classname)
18751882
# sorting fails if the value contains
18761883
# items not yet stored in the database

0 commit comments

Comments
 (0)