diff roundup/cgi/templating.py @ 2048:c0961f42d8f3 maint-0.6

Made error on create consistent with edit when user enters invalid data... for Multilink and Link form fields [SF#904072]
author Richard Jones <richard@users.sourceforge.net>
date Wed, 25 Feb 2004 09:37:37 +0000
parents 0bbe74ce51d0
children d26e577f8a85
line wrap: on
line diff
--- a/roundup/cgi/templating.py	Wed Feb 25 04:24:48 2004 +0000
+++ b/roundup/cgi/templating.py	Wed Feb 25 09:37:37 2004 +0000
@@ -247,7 +247,10 @@
         l.sort()
         return [HTMLClass(self._client, cn) for cn in l]
 
-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:
@@ -256,9 +259,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:
@@ -316,11 +320,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/