[Checkins] SVN: grok/trunk/src/grok/components.py refactor dirty traversal hack

Jasper Spaans jspaans at thehealthagency.com
Sat May 3 17:22:39 EDT 2008


Log message for revision 86301:
  refactor dirty traversal hack

Changed:
  U   grok/trunk/src/grok/components.py

-=-
Modified: grok/trunk/src/grok/components.py
===================================================================
--- grok/trunk/src/grok/components.py	2008-05-03 21:12:15 UTC (rev 86300)
+++ grok/trunk/src/grok/components.py	2008-05-03 21:22:39 UTC (rev 86301)
@@ -482,10 +482,15 @@
             result = traverse(name)
             if result is not None:
                 return result
-        # try to get the item from the container
-        return self.context.get(name)
+        # try to get the item from the container, casting it to an int
+        # if the key might be an int (which is quite reasonable for a
+        # key that lives in a database)
+        # XXX this is a dirty hack, but it works fine
+        try:
+            return self.context.get(type(self.context.keys()[0])(name))
+        except KeyError:
+            return self.context.get(name)
 
-
 default_form_template = PageTemplateFile(os.path.join(
     'templates', 'default_edit_form.pt'))
 default_form_template.__grok_name__ = 'default_edit_form'



More information about the Checkins mailing list