diff 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
line wrap: on
line diff
--- a/roundup/cgi/templating.py	Wed Feb 25 03:39:53 2004 +0000
+++ b/roundup/cgi/templating.py	Wed Feb 25 09:40:46 2004 +0000
@@ -276,7 +276,10 @@
             m.append(HTMLClass(self._client, item))
         return r
 
-def lookupIds(db, prop, ids, num_re=re.compile('-?\d+')):
+def lookupIds(db, prop, ids, fail_ok=False, num_re=re.compile('-?\d+')):
+    ''' "fail_ok" should be specified if we wish to pass through bad values
+        (most likely form values that we wish to represent back to the user)
+    '''
     cl = db.getclass(prop.classname)
     l = []
     for entry in ids:
@@ -285,9 +288,10 @@
         else:
             try:
                 l.append(cl.lookup(entry))
-            except KeyError:
-                # ignore invalid keys
-                pass
+            except (TypeError, KeyError):
+                if fail_ok:
+                    # pass through the bad value
+                    l.append(entry)
     return l
 
 class HTMLPermissions:
@@ -382,11 +386,12 @@
             if form.has_key(item):
                 if isinstance(prop, hyperdb.Multilink):
                     value = lookupIds(self._db, prop,
-                        handleListCGIValue(form[item]))
+                        handleListCGIValue(form[item]), fail_ok=True)
                 elif isinstance(prop, hyperdb.Link):
                     value = form[item].value.strip()
                     if value:
-                        value = lookupIds(self._db, prop, [value])[0]
+                        value = lookupIds(self._db, prop, [value],
+                            fail_ok=True)[0]
                     else:
                         value = None
                 else:

Roundup Issue Tracker: http://roundup-tracker.org/