[Checkins] SVN: grok/trunk/src/grok/ Support request form value dispatching to arguments of update(), just like in

Philipp von Weitershausen philikon at philikon.de
Fri Mar 16 14:24:02 EDT 2007


Log message for revision 73228:
  Support request form value dispatching to arguments of update(), just like in
  grok.View's update().
  

Changed:
  U   grok/trunk/src/grok/components.py
  U   grok/trunk/src/grok/ftests/form/update.py

-=-
Modified: grok/trunk/src/grok/components.py
===================================================================
--- grok/trunk/src/grok/components.py	2007-03-16 18:07:01 UTC (rev 73227)
+++ grok/trunk/src/grok/components.py	2007-03-16 18:24:01 UTC (rev 73228)
@@ -392,7 +392,7 @@
     render.base_method = True
 
     def __call__(self):
-        self.update()
+        mapply(self.update, (), self.request)
         if self.request.response.getStatus() in (302, 303):
             # A redirect was triggered somewhere in update().  Don't
             # continue rendering the template or doing anything else.

Modified: grok/trunk/src/grok/ftests/form/update.py
===================================================================
--- grok/trunk/src/grok/ftests/form/update.py	2007-03-16 18:07:01 UTC (rev 73227)
+++ grok/trunk/src/grok/ftests/form/update.py	2007-03-16 18:24:01 UTC (rev 73228)
@@ -32,6 +32,18 @@
   >>> print browser.contents
   Ellie, the Mammoth reports: The form's update() was called and my name was Manfred.
 
+A form's update() method may also take arbitrary parameters that will
+be filled with values from the request (such as form values):
+
+  >>> browser.open("http://localhost/manfred/editupdatewitharguments")
+  >>> browser.getControl(name="report").value = "Request argument dispatch to update() works."
+  >>> browser.getControl(name="form.name").value = "Mallie"
+  >>> browser.getControl("Apply").click()
+
+  >>> browser.open("http://localhost/manfred")
+  >>> print browser.contents
+  Mallie, the Mammoth reports: Request argument dispatch to update() works.
+
 """
 import grok
 from zope import schema
@@ -58,3 +70,21 @@
         # redirect upon form submit so that no changes are ever saved
         if 'form.name' in self.request:
             self.redirect(self.url('index'))
+
+class EditUpdateWithArguments(grok.EditForm):
+
+    def update(self, report=None):
+        if report is not None:
+            self.context.report = report
+
+editupdatewitharguments = grok.PageTemplate("""
+<html>
+<body>
+<form action="" tal:attributes="action request/URL">
+  <input type="text" name="report" />
+  <div tal:repeat="widget view/widgets" tal:content="structure widget" />
+  <div tal:repeat="action view/actions" tal:content="structure action/render" />
+</form>
+</body>
+</html>
+""")



More information about the Checkins mailing list