[Checkins] SVN: grok/trunk/doc/ Second stage of simple forms conversion to sample app.

Martijn Faassen faassen at infrae.com
Sat Mar 17 06:51:45 EDT 2007


Log message for revision 73279:
  Second stage of simple forms conversion to sample app.
  

Changed:
  A   grok/trunk/doc/groktut/simple_forms2/
  U   grok/trunk/doc/groktut/simple_forms2/src/sample/app.py
  U   grok/trunk/doc/tutorial.txt

-=-
Copied: grok/trunk/doc/groktut/simple_forms2 (from rev 73278, grok/trunk/doc/groktut/simple_forms)

Modified: grok/trunk/doc/groktut/simple_forms2/src/sample/app.py
===================================================================
--- grok/trunk/doc/groktut/simple_forms/src/sample/app.py	2007-03-17 10:45:50 UTC (rev 73278)
+++ grok/trunk/doc/groktut/simple_forms2/src/sample/app.py	2007-03-17 10:51:44 UTC (rev 73279)
@@ -4,5 +4,11 @@
     pass
 
 class Index(grok.View):
-    def update(self, value1=0, value2=0):
-        self.sum = int(value1) + int(value2)
+    def update(self, value1=None, value2=None):
+        try:
+            value1 = int(value1)
+            value2 = int(value2)
+        except (TypeError, ValueError):
+            self.sum = "No sum"
+            return
+        self.sum = value1 + value2

Modified: grok/trunk/doc/tutorial.txt
===================================================================
--- grok/trunk/doc/tutorial.txt	2007-03-17 10:45:50 UTC (rev 73278)
+++ grok/trunk/doc/tutorial.txt	2007-03-17 10:51:44 UTC (rev 73279)
@@ -683,6 +683,13 @@
 Simple forms
 ------------
 
+.. sidebar:: Automatic forms
+
+  Creating forms and converting and validating user input by hand, as
+  shown in this section, can be rather cumbersome. With Grok, you can
+  use Zope 3's *schema* and *formlib* systems to automate this and
+  more. This will be discussed in a later section. XXX
+
 Entering the parameters through URLs is not very pretty. Let's use a
 form for this instead. Change ``index.pt`` to contain a form, like
 this:
@@ -713,26 +720,14 @@
 This is because the parameters were empty strings, which cannot be
 converted to integers. Another thing that is not really pretty is that
 it displays a sum (0) even if we did not enter any data. Let's change
-``app.py`` to take both cases into account::
+``app.py`` to take both cases into account:
 
-  import grok
+.. include:: groktut/simple_forms2/src/sample/app.py
+  :literal:
 
-  class Sample(grok.Application, grok.Container):
-      pass
-
-  class Index(grok.View):
-      def update(self, value1=None, value2=None):
-          try:
-              value1 = int(value1)
-              value2 = int(value2)
-          except (TypeError, ValueError):
-              self.sum = "No sum yet"
-              return
-          self.sum = value1 + value2
-
 We catch any TypeError and ValueError here so that wrong or missing
-data does not result in a failure. Instead we display the text "No sum
-yet". If we don't get any error, the conversion to integer was fine,
+data does not result in a failure. Instead we display the text "No
+sum". If we don't get any error, the conversion to integer was fine,
 and we can display the sum.
 
 Restart Zope and go to the form again to try it out:



More information about the Checkins mailing list