@@ -276,7 +276,10 @@ def classes(self):
276276 m .append (HTMLClass (self ._client , item ))
277277 return r
278278
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+ '''
280283 cl = db .getclass (prop .classname )
281284 l = []
282285 for entry in ids :
@@ -285,9 +288,10 @@ def lookupIds(db, prop, ids, num_re=re.compile('-?\d+')):
285288 else :
286289 try :
287290 l .append (cl .lookup (entry ))
288- except KeyError :
289- # ignore invalid keys
290- pass
291+ except (TypeError , KeyError ):
292+ if fail_ok :
293+ # pass through the bad value
294+ l .append (entry )
291295 return l
292296
293297class HTMLPermissions :
@@ -382,11 +386,12 @@ def __getitem__(self, item):
382386 if form .has_key (item ):
383387 if isinstance (prop , hyperdb .Multilink ):
384388 value = lookupIds (self ._db , prop ,
385- handleListCGIValue (form [item ]))
389+ handleListCGIValue (form [item ]), fail_ok = True )
386390 elif isinstance (prop , hyperdb .Link ):
387391 value = form [item ].value .strip ()
388392 if value :
389- value = lookupIds (self ._db , prop , [value ])[0 ]
393+ value = lookupIds (self ._db , prop , [value ],
394+ fail_ok = True )[0 ]
390395 else :
391396 value = None
392397 else :
0 commit comments