[Checkins] SVN: grok/trunk/doc/ Make redirection section a sample too.

Martijn Faassen faassen at infrae.com
Sat Mar 17 11:22:37 EDT 2007


Log message for revision 73295:
  Make redirection section a sample too.
  

Changed:
  A   grok/trunk/doc/groktut/redirection/
  U   grok/trunk/doc/groktut/redirection/src/sample/app.py
  A   grok/trunk/doc/groktut/redirection/src/sample/app_templates/
  A   grok/trunk/doc/groktut/redirection/src/sample/app_templates/edit.pt
  A   grok/trunk/doc/groktut/redirection/src/sample/app_templates/index.pt
  U   grok/trunk/doc/tutorial.txt

-=-
Copied: grok/trunk/doc/groktut/redirection (from rev 73293, grok/trunk/doc/groktut/storing_data)

Modified: grok/trunk/doc/groktut/redirection/src/sample/app.py
===================================================================
--- grok/trunk/doc/groktut/storing_data/src/sample/app.py	2007-03-17 15:16:09 UTC (rev 73293)
+++ grok/trunk/doc/groktut/redirection/src/sample/app.py	2007-03-17 15:22:37 UTC (rev 73295)
@@ -11,3 +11,4 @@
         if text is None:
             return
         self.context.text = text
+        self.redirect(self.url('index'))

Added: grok/trunk/doc/groktut/redirection/src/sample/app_templates/edit.pt
===================================================================
--- grok/trunk/doc/groktut/storing_data/src/sample/app_templates/edit.pt	2007-03-17 15:16:09 UTC (rev 73293)
+++ grok/trunk/doc/groktut/redirection/src/sample/app_templates/edit.pt	2007-03-17 15:22:37 UTC (rev 73295)
@@ -0,0 +1,8 @@
+<html>
+<body>
+<form tal:attributes="action view/url" method="POST">
+Text to store: <input type="text" name="text" value="" /><br />
+<input type="submit" value="Store" />
+</form>
+</body>
+</html>

Added: grok/trunk/doc/groktut/redirection/src/sample/app_templates/index.pt
===================================================================
--- grok/trunk/doc/groktut/storing_data/src/sample/app_templates/index.pt	2007-03-17 15:16:09 UTC (rev 73293)
+++ grok/trunk/doc/groktut/redirection/src/sample/app_templates/index.pt	2007-03-17 15:22:37 UTC (rev 73295)
@@ -0,0 +1,6 @@
+<html>
+<body>
+<p>The text: <span tal:replace="python:context.text">text</span></p>
+<p><a tal:attributes="href python:view.url('edit')">Edit this page</a></p>
+</body>
+</html>

Modified: grok/trunk/doc/tutorial.txt
===================================================================
--- grok/trunk/doc/tutorial.txt	2007-03-17 15:22:01 UTC (rev 73294)
+++ grok/trunk/doc/tutorial.txt	2007-03-17 15:22:37 UTC (rev 73295)
@@ -892,37 +892,21 @@
 
 Let's make our application a bit easier to use. First, let's change
 ``index.pt`` so it includes a link to the edit page. To do this, we
-will use the ``url`` method on the view::
+will use the ``url`` method on the view:
 
-  <html>
-  <body>
-  <p>The text: <span tal:replace="python:context.text">text</span></p>
-  <p><a tal:attributes="href python:view.url('edit')">Edit this page</a></p>
-  </body>
-  </html>
+.. include:: groktut/redirection/src/sample/app_templates/index.pt
+  :literal:
 
 Giving ``url`` a single string argument will generate a URL to the
 view named that way on the same object (``test``), so in this case
 ``test/edit``.
 
 Now let's change the edit form so that it redirects back to the
-``index`` page after you press the submit button::
+``index`` page after you press the submit button:
 
-  import grok
+.. include:: groktut/redirection/src/sample/app.py
+  :literal:
 
-  class Sample(grok.Application, grok.Container):
-      text = 'default text'
-
-  class Index(grok.View):
-      pass
-
-  class Edit(grok.View):
-      def update(self, text=None):
-          if text is None:
-              return
-          self.context.text = text
-          self.redirect(self.url('index'))
-
 The last line is the new one. We use the ``url`` method on the view to
 construct a URL to the ``index`` page. Since we're in the template, we
 can simply call ``url`` on ``self``. Then, we pass this to another



More information about the Checkins mailing list