@@ -247,7 +247,10 @@ def classes(self):
247247 l .sort ()
248248 return [HTMLClass (self ._client , cn ) for cn in l ]
249249
250- def lookupIds (db , prop , ids , num_re = re .compile ('-?\d+' )):
250+ def lookupIds (db , prop , ids , fail_ok = False , num_re = re .compile ('-?\d+' )):
251+ ''' "fail_ok" should be specified if we wish to pass through bad values
252+ (most likely form values that we wish to represent back to the user)
253+ '''
251254 cl = db .getclass (prop .classname )
252255 l = []
253256 for entry in ids :
@@ -256,9 +259,10 @@ def lookupIds(db, prop, ids, num_re=re.compile('-?\d+')):
256259 else :
257260 try :
258261 l .append (cl .lookup (entry ))
259- except KeyError :
260- # ignore invalid keys
261- pass
262+ except (TypeError , KeyError ):
263+ if fail_ok :
264+ # pass through the bad value
265+ l .append (entry )
262266 return l
263267
264268class HTMLPermissions :
@@ -316,11 +320,12 @@ def __getitem__(self, item):
316320 if form .has_key (item ):
317321 if isinstance (prop , hyperdb .Multilink ):
318322 value = lookupIds (self ._db , prop ,
319- handleListCGIValue (form [item ]))
323+ handleListCGIValue (form [item ]), fail_ok = True )
320324 elif isinstance (prop , hyperdb .Link ):
321325 value = form [item ].value .strip ()
322326 if value :
323- value = lookupIds (self ._db , prop , [value ])[0 ]
327+ value = lookupIds (self ._db , prop , [value ],
328+ fail_ok = True )[0 ]
324329 else :
325330 value = None
326331 else :
0 commit comments