[Checkins] SVN: grok/branches/luciano-tutorial/doc/ fixes to chapters: redirecion, the_rules_of_persistence, showing_the_value_in_the_form, storing_data

Luciano Ramalho luciano at ramalho.org
Sat Jul 14 14:21:32 EDT 2007


Log message for revision 77978:
  fixes to chapters: redirecion, the_rules_of_persistence, showing_the_value_in_the_form, storing_data
  

Changed:
  U   grok/branches/luciano-tutorial/doc/groktut/redirection/src/pebbles/app.py
  U   grok/branches/luciano-tutorial/doc/groktut/redirection/src/pebbles/app_templates/index.pt
  U   grok/branches/luciano-tutorial/doc/groktut/showing_the_value_in_the_form/src/pebbles/app_templates/index.pt
  U   grok/branches/luciano-tutorial/doc/groktut/storing_data/src/pebbles/app_templates/index.pt
  U   grok/branches/luciano-tutorial/doc/groktut/the_rules_of_persistence/src/pebbles/app.py
  U   grok/branches/luciano-tutorial/doc/groktut/the_rules_of_persistence/src/pebbles/app_templates/index.pt
  U   grok/branches/luciano-tutorial/doc/tutorial.txt

-=-
Modified: grok/branches/luciano-tutorial/doc/groktut/redirection/src/pebbles/app.py
===================================================================
--- grok/branches/luciano-tutorial/doc/groktut/redirection/src/pebbles/app.py	2007-07-14 18:18:41 UTC (rev 77977)
+++ grok/branches/luciano-tutorial/doc/groktut/redirection/src/pebbles/app.py	2007-07-14 18:21:32 UTC (rev 77978)
@@ -1,14 +1,14 @@
 import grok
 
 class Pebbles(grok.Application, grok.Container):
-    quantity = 0
+    mammoths = 0
 
 class Index(grok.View):
     pass # see app_templates/index.pt
     
 class Edit(grok.View):
-    def update(self, quantity=None):
-        if quantity is None:
+    def update(self, number=None):
+        if number is None:
             return
-        self.context.quantity = quantity
+        self.context.mammoths = number
         self.redirect(self.url('index'))
\ No newline at end of file

Modified: grok/branches/luciano-tutorial/doc/groktut/redirection/src/pebbles/app_templates/index.pt
===================================================================
--- grok/branches/luciano-tutorial/doc/groktut/redirection/src/pebbles/app_templates/index.pt	2007-07-14 18:18:41 UTC (rev 77977)
+++ grok/branches/luciano-tutorial/doc/groktut/redirection/src/pebbles/app_templates/index.pt	2007-07-14 18:21:32 UTC (rev 77978)
@@ -1,10 +1,7 @@
 <html>
-<head>
-</head>
 <body>
-	<p>The quantity: <span tal:replace="python:context.quantity">999</span></p>
+	<p>Mammoths seen: <span tal:replace="context/mammoths">999</span></p>
 
-	<p><a tal:attributes="href python:view.url('edit')">Edit this page</a></p>
-
+	<p><a tal:attributes="href python:view.url('edit')">Add</a></p>
 </body>
 </html>

Modified: grok/branches/luciano-tutorial/doc/groktut/showing_the_value_in_the_form/src/pebbles/app_templates/index.pt
===================================================================
--- grok/branches/luciano-tutorial/doc/groktut/showing_the_value_in_the_form/src/pebbles/app_templates/index.pt	2007-07-14 18:18:41 UTC (rev 77977)
+++ grok/branches/luciano-tutorial/doc/groktut/showing_the_value_in_the_form/src/pebbles/app_templates/index.pt	2007-07-14 18:21:32 UTC (rev 77978)
@@ -1,6 +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>
+	<p>Mammoths seen: <span tal:replace="context/mammoths">999</span></p>
+
 </body>
 </html>

Modified: grok/branches/luciano-tutorial/doc/groktut/storing_data/src/pebbles/app_templates/index.pt
===================================================================
--- grok/branches/luciano-tutorial/doc/groktut/storing_data/src/pebbles/app_templates/index.pt	2007-07-14 18:18:41 UTC (rev 77977)
+++ grok/branches/luciano-tutorial/doc/groktut/storing_data/src/pebbles/app_templates/index.pt	2007-07-14 18:21:32 UTC (rev 77978)
@@ -2,7 +2,7 @@
 <head>
 </head>
 <body>
-	<p>Mammoths seen: <span tal:replace="python:context.mammoths">999</span></p>
+	<p>Mammoths seen: <span tal:replace="context/mammoths">999</span></p>
 
 </body>
 </html>

Modified: grok/branches/luciano-tutorial/doc/groktut/the_rules_of_persistence/src/pebbles/app.py
===================================================================
--- grok/branches/luciano-tutorial/doc/groktut/the_rules_of_persistence/src/pebbles/app.py	2007-07-14 18:18:41 UTC (rev 77977)
+++ grok/branches/luciano-tutorial/doc/groktut/the_rules_of_persistence/src/pebbles/app.py	2007-07-14 18:21:32 UTC (rev 77978)
@@ -3,15 +3,15 @@
 class Pebbles(grok.Application, grok.Container):
     def __init__(self):
         super(Pebbles, self).__init__()
-        self.gifts = []
+        self.mammoths = []
     
 class Index(grok.View):
     pass
 
 class Edit(grok.View):
-    def update(self, text=None):
-        if text is None:
+    def update(self, name=None):
+        if name is None:
             return
         # this code has a BUG!
-        self.context.incomes.append(text)
+        self.context.mammoths.append(name)
         self.redirect(self.url('index'))

Modified: grok/branches/luciano-tutorial/doc/groktut/the_rules_of_persistence/src/pebbles/app_templates/index.pt
===================================================================
--- grok/branches/luciano-tutorial/doc/groktut/the_rules_of_persistence/src/pebbles/app_templates/index.pt	2007-07-14 18:18:41 UTC (rev 77977)
+++ grok/branches/luciano-tutorial/doc/groktut/the_rules_of_persistence/src/pebbles/app_templates/index.pt	2007-07-14 18:21:32 UTC (rev 77978)
@@ -1,9 +1,10 @@
 <html>
 <body>
-We store the following quantities:
+<p>Mammoths seen:</p>
 <ul>
-  <li tal:repeat="qty python:context.gifts" tal:content="qty"></li>
+  <li tal:repeat="name context/mammoths" tal:content="name"></li>
 </ul>
-<a tal:attributes="href python:view.url('edit')">Add a number</a>
+<p><a tal:attributes="href python:view.url('edit')">Add</a></p>
 </body>
 </html>
+

Modified: grok/branches/luciano-tutorial/doc/tutorial.txt
===================================================================
--- grok/branches/luciano-tutorial/doc/tutorial.txt	2007-07-14 18:18:41 UTC (rev 77977)
+++ grok/branches/luciano-tutorial/doc/tutorial.txt	2007-07-14 18:21:32 UTC (rev 77978)
@@ -984,7 +984,7 @@
   :literal:
 
 The only change is that we have used ``tal:attributes`` to include the
-value of the ``quantity`` attribute of the context object in the form.
+value of the ``mammoths`` attribute of the context object in the form.
 
 Redirection
 -----------
@@ -1000,6 +1000,16 @@
 view named that way on the same object (``test``), so in this case
 ``test/edit``.
 
+.. sidebar: ZPT: Python and path expressions
+
+  The attribute language of Zope Page Templates allows a few different
+  syntaxes. The most commonly used are path expressions (the default) and
+  Python expressions (defined with the ``python:`` prefix).
+  ``context/mammoths`` is an example of a path expression. It's Python
+  equivalent would be ``python:context/mammoths``. If you need to pass
+  an argument to a method, you must use the Python syntax, like in the
+  current example: ``python:view.url('edit')``.
+
 Now let's change the edit form so that it redirects back to the
 ``index`` page after you press the submit button:
 
@@ -1048,24 +1058,24 @@
 
 If we use a mutable object such as a list or dictionary to store data
 instead, we do need to take special action. Let's change our example
-code (based on the last section) to use a mutable object (a list):
+code (based on the last section) to use a mutable object (a list
+to store mammoth names):
 
 .. include:: groktut/the_rules_of_persistence/src/pebbles/app.py
   :literal:
 
 We have now changed the ``Pebbles`` class to do something new: it has
 an ``__init__`` method. Whenever you create the ``Pebbles`` application
-object now, it will be created with an attribute called ``list``,
+object now, it will be created with an attribute called ``mammoths``,
 which will contain an empty Python list. 
 
 We also make sure that the ``__init__`` method of the superclass still
 gets executed, by using the regular Python ``super`` idiom. If we
 didn't do that, our container would not be fully initialized.
 
-You will also notice a small change to the ``update`` method of the
-``Edit`` class. Instead of just storing the quantity as an attribute of
-our ``Pebbles`` model, we append each entered number to the 
-``gifts`` attribute. 
+You will also notice a small change to the ``update`` method of the ``Edit``
+class. Instead of just storing a number of mammoths as an attribute of our
+``Pebbles`` model, we append each entered name to the ``mammoths`` attribute.
 
 Note that this code has a subtle bug in it, which is why we've added
 the comment. We will see what bug this is in a little bit. First,
@@ -1306,12 +1316,6 @@
 of the items in the container. We create a link to these items using
 ``view/url``.
 
-.. sidebar: ZPT: Python and path expressions
-
-  In the TAL syntax of Zope Page Templates, the expression
-  "python:container.keys()" can be written simply as "container/keys"
-  using the path syntax. 
-
 Creating mammoths
 -------------------
 



More information about the Checkins mailing list