I've appended to this email a patch for clearing a form after it has been processed so it can be rendered again in one request. After some light unit testing, it seems to work well. Intended usage is:

form = self.build_some_form() # Form will post back to this exported method.
if form.is_submitted() and not form.has_errors():
    # process form....
    form.clear()
form.render()

If you use the prefix keyword on the Form constructor, you can mix many of these in one exported method.

Dave

---------------

--- form.qpy.orig       2007-11-16 17:39:01.000000000 -0600
+++ form.qpy    2007-11-16 18:54:05.000000000 -0600
@@ -200,6 +200,11 @@
                     has_errors =  True
         return has_errors

+    def clear(self):
+        request = get_request()
+        for widget in self:
+            widget.clear(request)
+
     def clear_errors(self):
"""Ensure that all components of the form have parsed themselves.
         Clear any errors that might have occurred during parsing.

--- widget.qpy.orig     2007-11-16 17:47:33.000000000 -0600
+++ widget.qpy  2007-11-16 18:57:20.000000000 -0600
@@ -147,6 +147,15 @@
         else:
             self.value = None

+    def clear(self, request=None):
+        if request is None:
+            request = get_request()
+        if self.name in request.get_fields():
+            del request.get_fields()[self.name]
+        if self._parsed:
+            self._parse(request)
+
     def render_title [html] (self, title):
         if title:
             '\n'

_______________________________________________
QP mailing list
[email protected]
http://mail.mems-exchange.org/mailman/listinfo/qp

Reply via email to