[Checkins] SVN: grok/branches/luciano-tutorial/doc/ fixing wrong
code include reference and several typos
Luciano Ramalho
luciano at ramalho.org
Sat Jul 14 11:43:38 EDT 2007
Log message for revision 77943:
fixing wrong code include reference and several typos
Changed:
A grok/branches/luciano-tutorial/doc/groktut/crud3/
D grok/branches/luciano-tutorial/doc/groktut/crud3/src/pebbles/app.py
A grok/branches/luciano-tutorial/doc/groktut/crud3/src/pebbles/app.py
U grok/branches/luciano-tutorial/doc/groktut/crud3/src/pebbles/app_templates/index.pt
D grok/branches/luciano-tutorial/doc/groktut/crud3/src/pebbles/app_templates/mammothdetails.pt
A grok/branches/luciano-tutorial/doc/groktut/crud3/src/pebbles/app_templates/mammothdetails.pt
U grok/branches/luciano-tutorial/doc/groktut/showing_the_value_in_the_form/setup.py
A grok/branches/luciano-tutorial/doc/groktut/showing_the_value_in_the_form/src/pebbles/
U grok/branches/luciano-tutorial/doc/groktut/showing_the_value_in_the_form/src/pebbles/app.py
U grok/branches/luciano-tutorial/doc/groktut/showing_the_value_in_the_form/src/pebbles/app_templates/edit.pt
D grok/branches/luciano-tutorial/doc/groktut/showing_the_value_in_the_form/src/sample/
U grok/branches/luciano-tutorial/doc/groktut/storing_data/src/pebbles/app.py
U grok/branches/luciano-tutorial/doc/groktut/storing_data/src/pebbles/app_templates/edit.pt
U grok/branches/luciano-tutorial/doc/groktut/storing_data/src/pebbles/app_templates/index.pt
U grok/branches/luciano-tutorial/doc/tutorial.txt
-=-
Copied: grok/branches/luciano-tutorial/doc/groktut/crud3 (from rev 77887, grok/branches/luciano-tutorial/doc/groktut/crud2)
Deleted: grok/branches/luciano-tutorial/doc/groktut/crud3/src/pebbles/app.py
===================================================================
--- grok/branches/luciano-tutorial/doc/groktut/crud2/src/pebbles/app.py 2007-07-13 21:15:54 UTC (rev 77887)
+++ grok/branches/luciano-tutorial/doc/groktut/crud3/src/pebbles/app.py 2007-07-14 15:43:38 UTC (rev 77943)
@@ -1,45 +0,0 @@
-import grok
-from zope import interface, schema
-
-class Pebbles(grok.Application, grok.Container):
-
- def addMammoth(self, name, weight):
- self[name] = Mammoth(name, weight)
-
- def eatMammoth(self, name):
- del self[name]
-
-class Index(grok.View):
- grok.context(Pebbles)
-
- def update(self, name=None, weight=0):
- if name is None:
- return
- self.context.addMammoth(name, weight)
- self.redirect(self.url('index'))
-
-class Eat(grok.View):
- grok.context(Pebbles)
- def render(self, names):
- for name in names:
- self.context.eatMammoth(name)
- self.redirect(self.url('index'))
-
-class IMammoth(interface.Interface):
- name = schema.TextLine(title=u"Name", required=True)
- weight = schema.Int(title=u'Weight', min=0)
-
-class Mammoth(grok.Model):
- #implements(IMammoth)
- def __init__(self, name, weight):
- self.name = name
- self.weight = weight
-
-class MammothDetails(grok.View):
- grok.context(Mammoth)
- grok.name('index')
-
-class Edit(grok.EditForm):
- grok.context(Mammoth)
- pass
-
Copied: grok/branches/luciano-tutorial/doc/groktut/crud3/src/pebbles/app.py (from rev 77890, grok/branches/luciano-tutorial/doc/groktut/crud2/src/pebbles/app.py)
===================================================================
--- grok/branches/luciano-tutorial/doc/groktut/crud3/src/pebbles/app.py (rev 0)
+++ grok/branches/luciano-tutorial/doc/groktut/crud3/src/pebbles/app.py 2007-07-14 15:43:38 UTC (rev 77943)
@@ -0,0 +1,49 @@
+import grok
+from zope import interface, schema
+
+class Pebbles(grok.Application, grok.Container):
+
+ def addMammoth(self, name, weight):
+ self[name] = Mammoth(name, weight)
+
+ def eatMammoth(self, name):
+ del self[name]
+
+class Index(grok.View):
+ grok.context(Pebbles)
+
+class Eat(grok.View):
+ grok.context(Pebbles)
+ def render(self, names):
+ for name in names:
+ self.context.eatMammoth(name)
+ self.redirect(self.url('index'))
+
+class IMammoth(interface.Interface):
+ name = schema.TextLine(title=u"Name", required=True)
+ weight = schema.Int(title=u'Weight', min=0)
+
+class Mammoth(grok.Model):
+ interface.implements(IMammoth)
+ def __init__(self, name, weight):
+ self.name = name
+ self.weight = weight
+
+class MammothDetails(grok.View):
+ grok.context(Mammoth)
+ grok.name('index')
+
+class Edit(grok.EditForm):
+ grok.context(Mammoth)
+
+class AddMammoth(grok.AddForm):
+ grok.context(Pebbles)
+ form_fields = grok.AutoFields(Mammoth)
+
+ @grok.action('Add mammoth')
+ def add(self, name, weight):
+ mammoth = Mammoth(name, weight)
+ self.context[name] = mammoth
+ self.redirect(self.url(self.context))
+
+
Modified: grok/branches/luciano-tutorial/doc/groktut/crud3/src/pebbles/app_templates/index.pt
===================================================================
--- grok/branches/luciano-tutorial/doc/groktut/crud2/src/pebbles/app_templates/index.pt 2007-07-13 21:15:54 UTC (rev 77887)
+++ grok/branches/luciano-tutorial/doc/groktut/crud3/src/pebbles/app_templates/index.pt 2007-07-14 15:43:38 UTC (rev 77943)
@@ -14,12 +14,7 @@
</ul>
<input type="submit" value="Eat">
</form>
- <h2>New mammoth</h2>
- <form tal:attributes="action view/url" method="POST">
- Name: <input type="text" name="name" value="" /><br />
- Weight: <input type="text" name="weight" value="" /><br />
- <input type="submit" value="Add mammoth" />
- </form>
+ <p><a tal:attributes="href python:view.url('addmammoth')">Add mammoth</a></p>
</body>
</html>
Deleted: grok/branches/luciano-tutorial/doc/groktut/crud3/src/pebbles/app_templates/mammothdetails.pt
===================================================================
--- grok/branches/luciano-tutorial/doc/groktut/crud2/src/pebbles/app_templates/mammothdetails.pt 2007-07-13 21:15:54 UTC (rev 77887)
+++ grok/branches/luciano-tutorial/doc/groktut/crud3/src/pebbles/app_templates/mammothdetails.pt 2007-07-14 15:43:38 UTC (rev 77943)
@@ -1,8 +0,0 @@
-<html>
-<head>
-</head>
-<body>
- <h2>Mammoth "<span tal:replace="python:context.name"></span>"</h2>
- <p>Weight: <span tal:replace="context/weight">999</span> stones.</p>
-</body>
-</html>
Copied: grok/branches/luciano-tutorial/doc/groktut/crud3/src/pebbles/app_templates/mammothdetails.pt (from rev 77890, grok/branches/luciano-tutorial/doc/groktut/crud2/src/pebbles/app_templates/mammothdetails.pt)
===================================================================
--- grok/branches/luciano-tutorial/doc/groktut/crud3/src/pebbles/app_templates/mammothdetails.pt (rev 0)
+++ grok/branches/luciano-tutorial/doc/groktut/crud3/src/pebbles/app_templates/mammothdetails.pt 2007-07-14 15:43:38 UTC (rev 77943)
@@ -0,0 +1,10 @@
+<html>
+<head>
+</head>
+<body>
+ <h2>Mammoth "<span tal:replace="python:context.name"></span>"</h2>
+ <p>Weight: <span tal:replace="context/weight">999</span> stones.</p>
+
+ <p><a tal:attributes="href python:view.url('edit')" >Edit</a></p>
+</body>
+</html>
Modified: grok/branches/luciano-tutorial/doc/groktut/showing_the_value_in_the_form/setup.py
===================================================================
--- grok/branches/luciano-tutorial/doc/groktut/showing_the_value_in_the_form/setup.py 2007-07-14 15:42:23 UTC (rev 77942)
+++ grok/branches/luciano-tutorial/doc/groktut/showing_the_value_in_the_form/setup.py 2007-07-14 15:43:38 UTC (rev 77943)
@@ -2,7 +2,7 @@
version = 0.0
-setup(name='Sample',
+setup(name='Pebbles',
version=version,
description="",
long_description="""\
Copied: grok/branches/luciano-tutorial/doc/groktut/showing_the_value_in_the_form/src/pebbles (from rev 77786, grok/branches/luciano-tutorial/doc/groktut/showing_the_value_in_the_form/src/sample)
Modified: grok/branches/luciano-tutorial/doc/groktut/showing_the_value_in_the_form/src/pebbles/app.py
===================================================================
--- grok/branches/luciano-tutorial/doc/groktut/showing_the_value_in_the_form/src/sample/app.py 2007-07-12 19:41:41 UTC (rev 77786)
+++ grok/branches/luciano-tutorial/doc/groktut/showing_the_value_in_the_form/src/pebbles/app.py 2007-07-14 15:43:38 UTC (rev 77943)
@@ -1,14 +1,13 @@
import grok
-class Sample(grok.Application, grok.Container):
- text = 'default text'
+class Pebbles(grok.Application, grok.Container):
+ mammoths = 0
class Index(grok.View):
- pass
-
+ pass # see app_templates/index.pt
+
class Edit(grok.View):
- def update(self, text=None):
- if text is None:
+ def update(self, number=None):
+ if number is None:
return
- self.context.text = text
- self.redirect(self.url('index'))
+ self.context.mammoths = number
\ No newline at end of file
Modified: grok/branches/luciano-tutorial/doc/groktut/showing_the_value_in_the_form/src/pebbles/app_templates/edit.pt
===================================================================
--- grok/branches/luciano-tutorial/doc/groktut/showing_the_value_in_the_form/src/sample/app_templates/edit.pt 2007-07-12 19:41:41 UTC (rev 77786)
+++ grok/branches/luciano-tutorial/doc/groktut/showing_the_value_in_the_form/src/pebbles/app_templates/edit.pt 2007-07-14 15:43:38 UTC (rev 77943)
@@ -1,8 +1,10 @@
<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" />
+ Number of mammoths: <input type="text" name="number" value=""
+ tal:attributes="value context/mammoths"
+ ><br />
+ <input type="submit" value="Remember" />
</form>
</body>
-</html>
+</html>
\ No newline at end of file
Modified: grok/branches/luciano-tutorial/doc/groktut/storing_data/src/pebbles/app.py
===================================================================
--- grok/branches/luciano-tutorial/doc/groktut/storing_data/src/pebbles/app.py 2007-07-14 15:42:23 UTC (rev 77942)
+++ grok/branches/luciano-tutorial/doc/groktut/storing_data/src/pebbles/app.py 2007-07-14 15:43:38 UTC (rev 77943)
@@ -1,13 +1,13 @@
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
\ No newline at end of file
+ self.context.mammoths = number
\ No newline at end of file
Modified: grok/branches/luciano-tutorial/doc/groktut/storing_data/src/pebbles/app_templates/edit.pt
===================================================================
--- grok/branches/luciano-tutorial/doc/groktut/storing_data/src/pebbles/app_templates/edit.pt 2007-07-14 15:42:23 UTC (rev 77942)
+++ grok/branches/luciano-tutorial/doc/groktut/storing_data/src/pebbles/app_templates/edit.pt 2007-07-14 15:43:38 UTC (rev 77943)
@@ -1,9 +1,8 @@
<html>
<body>
<form tal:attributes="action view/url" method="POST">
- Quantity to remember: <input type="text" name="quantity" value=""
- tal:attributes="value context/quantity"/><br />
- <input type="submit" value="Store" />
+ Number of mammoths: <input type="text" name="number" value=""><br />
+ <input type="submit" value="Remember" />
</form>
</body>
</html>
\ No newline at end of file
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 15:42:23 UTC (rev 77942)
+++ grok/branches/luciano-tutorial/doc/groktut/storing_data/src/pebbles/app_templates/index.pt 2007-07-14 15:43:38 UTC (rev 77943)
@@ -2,7 +2,7 @@
<head>
</head>
<body>
- <p>The quantity: <span tal:replace="python:context.quantity">999</span></p>
+ <p>Mammoths seen: <span tal:replace="python:context.mammoths">999</span></p>
</body>
</html>
Modified: grok/branches/luciano-tutorial/doc/tutorial.txt
===================================================================
--- grok/branches/luciano-tutorial/doc/tutorial.txt 2007-07-14 15:42:23 UTC (rev 77942)
+++ grok/branches/luciano-tutorial/doc/tutorial.txt 2007-07-14 15:43:38 UTC (rev 77943)
@@ -908,35 +908,39 @@
Storing data
------------
-So far we have only displayed either hardcoded data, or calculations
-based on end-user input. What if we actually want to *store* some
-information, such as something the user entered? The easiest way to do
-this with Zope is to use the Zope Object Database (ZODB).
+So far we have only displayed either hardcoded data, or calculations based on
+end-user input. What if we actually want to *store* some information, such as
+something the user entered? The easiest way to do this with Zope is to use the
+Zope Object Database (ZODB).
-The ZODB is a database of Python objects. You can store any Python
-object in it, though you do need to follow a few simple rules (the
-"rules of persistence", which we will go into later). Our
-application objects are stored in the object database, so we can store
-some information on it.
+The ZODB is a database of Python objects. You can store any Python object in
+it, though you do need to follow a few simple rules (the "rules of
+persistence", which we will go into later). Our application objects are stored
+in the object database, so we can store some information on it.
-Let's create a primitive application that stores a number for us. We will call it ``Pebbles``, after the computing devices used by cavemen. We will use one view to view the number (``index``) and another to edit it (``edit``). Use ``grokproject`` to create a new application called ``Pebbles``, then modify it's ``app.py`` to read like this:
+Let's create a primitive application that stores a number for us. We will call
+it ``Pebbles``, after the computing devices of the stone age. This app could
+be used by a caveman to remember the number of mammoths in his herd. We will
+use one view to show the number (``index``) and another to edit it (``edit``).
+Use ``grokproject`` to create a new application called ``Pebbles``, then
+modify it's ``app.py`` to read like this:
.. include:: groktut/storing_data/src/pebbles/app.py
:literal:
-The ``Pebbles`` class gained a class attribute with some default number.
+The ``Pebbles`` class gained a class attribute with a default number.
In the ``update`` method of the ``Edit`` view you can see we actually
-set the ``quantity`` attribute on the context, if a ``quantity``
-value was supplied by a form. This will set the ``quantity`` attribute on
+set the ``mammoths`` attribute on the context, if a ``number``
+value was supplied by a form. This will set the ``mammoths`` attribute on
the instance of the ``Pebbles`` object in the object database, and thus
-will override the default ``quantity`` class attribute.
+will override the default ``mammoths`` class attribute.
Change the ``index.pt`` template to read like this:
.. include:: groktut/storing_data/src/pebbles/app_templates/index.pt
:literal:
-This is a very simple template that just displays the ``quantity``
+This is a very simple template that just displays the ``mammoths``
attribute of the ``context`` object (our ``Pebbles`` instance).
Create an ``edit.pt`` template with the following content:
More information about the Checkins
mailing list