[Checkins] SVN: grok/trunk/doc/tutorial.txt Add a bit more text.
Martijn Faassen
faassen at infrae.com
Tue Mar 13 12:08:01 EDT 2007
Log message for revision 73155:
Add a bit more text.
Changed:
U grok/trunk/doc/tutorial.txt
-=-
Modified: grok/trunk/doc/tutorial.txt
===================================================================
--- grok/trunk/doc/tutorial.txt 2007-03-12 18:49:45 UTC (rev 73154)
+++ grok/trunk/doc/tutorial.txt 2007-03-13 16:07:59 UTC (rev 73155)
@@ -1030,8 +1030,8 @@
You can even restart Zope and go back to the index page, and your text
should still be there.
-Redirection and default form values
------------------------------------
+Redirection
+-----------
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
@@ -1072,6 +1072,30 @@
special method available on all ``grok.View`` subclasses,
``redirect``. We tell the system to redirect to the ``index`` page.
+Form value
+----------
+
+Let's change our application so it displays what we last entered in
+the edit form as well, not just in on the index page.
+
+To make this work, change edit.pt so it reads like this::
+
+ <html>
+ <body>
+ <form tal:attributes="action view/url" method="POST">
+ Text to store: <input type="text" name="text" tal:attributes="value python:context.text" value="" /><br />
+ <input type="submit" value="Store" />
+ </form>
+ </body>
+ </html>
+
+The only change is that we have used ``tal:attributes`` to include the
+value of the ``text`` attribute of the context object in the form.
+
+While we explain here on how to do this manually here, there is also
+an automatic way to do this, with many more features. For much more on
+this, see section XXX on EditForms.
+
The rules of persistence
------------------------
@@ -1094,7 +1118,7 @@
the special ``_p_changed`` attribute on that instance to
``True``. This is only necessary if that attribute is not
``Persistent`` itself. It is also not necessary when you create or
- overwrite an attribute directly using `=`.
+ overwrite an attribute directly using ``=``.
If you construct your application's content out of ``grok.Model`` and
``grok.Container`` subclasses you mostly follow the rules
@@ -1102,10 +1126,30 @@
find yourself modifying a Python list (with ``append``, for instance)
or dictionary (by storing a value in it).
-Here is an example::
+The code in the section `Storing data`_ is a simple example. As you can
+see there, we have to do nothing special to obey the rules of
+persistence in this case.
- TDB
+If we use a mutable object instead, we do need to take special action. Let's
+change our example code to use a mutable object::
+ import grok
+
+ class Sample(grok.Application, grok.Model):
+ text = 'default text'
+
+ class Index(grok.View):
+ pass
+
+ class Edit(grok.View):
+ def update(self, text=None):
+ if text is None:
+ return
+ self.context.texts.append(text)
+ self.redirect(self.url('index'))
+
+XXX
+
Containers
----------
More information about the Checkins
mailing list