[Checkins] SVN: grok/branches/luciano-tutorial/doc/tutorial.txt
fixed even more broken includes
Luciano Ramalho
luciano at ramalho.org
Fri Jul 13 19:36:42 EDT 2007
Log message for revision 77893:
fixed even more broken includes
Changed:
U grok/branches/luciano-tutorial/doc/tutorial.txt
-=-
Modified: grok/branches/luciano-tutorial/doc/tutorial.txt
===================================================================
--- grok/branches/luciano-tutorial/doc/tutorial.txt 2007-07-13 23:27:20 UTC (rev 77892)
+++ grok/branches/luciano-tutorial/doc/tutorial.txt 2007-07-13 23:36:42 UTC (rev 77893)
@@ -256,7 +256,8 @@
the ``app.py`` file that grokproject said it would create. Let's look
at this file:
-.. include:: groktut/an_empty_grok_project/src/sample/app.py :literal:
+.. include:: groktut/an_empty_grok_project/src/sample/app.py
+ :literal:
Not very much yet, but enough to make an installable Grok application
and display its welcome page. We'll go into the details of what this
@@ -268,7 +269,8 @@
There is also a directory called ``app_templates``. It contains a single
template called ``index.pt``:
-.. include:: groktut/an_empty_grok_project/src/sample/app_templates/index.pt :literal:
+.. include:: groktut/an_empty_grok_project/src/sample/app_templates/index.pt
+ :literal:
This is the template for your project's welcome page.
@@ -278,7 +280,8 @@
typically completely ignore it, but we'll show it here once for good
measure:
-.. include:: groktut/an_empty_grok_project/src/sample/configure.zcml :literal:
+.. include:: groktut/an_empty_grok_project/src/sample/configure.zcml
+ :literal:
Showing pages
=============
@@ -319,7 +322,8 @@
Change the ``index.pt`` file to contain the following (very
simplistic) HTML:
-.. include:: groktut/publishing_a_simple_web_page/src/sample/app_templates/index.pt :literal:
+.. include:: groktut/publishing_a_simple_web_page/src/sample/app_templates/index.pt
+ :literal:
Then reload the page:
@@ -362,12 +366,14 @@
another template called ``bye.pt`` in ``app_templates``. Make it have
the following content:
-.. include:: groktut/a_second_view/src/sample/app_templates/bye.pt :literal:
+.. include:: groktut/a_second_view/src/sample/app_templates/bye.pt
+ :literal:
Now we need to tell Grok to actually use this template. To do this,
modify ``src/sample/app.py`` so that it reads like this:
-.. include:: groktut/a_second_view/src/sample/app.py :literal:
+.. include:: groktut/a_second_view/src/sample/app.py
+ :literal:
As you can see, all we did was add a class called ``Bye`` that
subclasses from ``grok.View``. This indicates to Grok that we want a
@@ -404,7 +410,8 @@
calculation inside ``index.pt`` template. Change the ``index.pt`` to
read like this:
-.. include:: groktut/making_our_page_dynamic/src/sample/app_templates/index.pt :literal:
+.. include:: groktut/making_our_page_dynamic/src/sample/app_templates/index.pt
+ :literal:
We've used the ``tal:content`` page template directive to replace the
content between the ``<p>`` and ``</p>`` tags with something else, in
@@ -442,12 +449,14 @@
package (so, ``src/sample/static``). In it, place a file called
``style.css`` and put in the following content:
-.. include:: groktut/static_resources_for_our_web_page/src/sample/static/style.css :literal:
+.. include:: groktut/static_resources_for_our_web_page/src/sample/static/style.css
+ :literal:
In order to use it, we also need to refer to it from our
``index.pt``. Change the content of ``index.pt`` to read like this:
-.. include:: groktut/static_resources_for_our_web_page/src/sample/app_templates/index.pt :literal:
+.. include:: groktut/static_resources_for_our_web_page/src/sample/app_templates/index.pt
+ :literal:
Now restart Zope and reload the page:
@@ -547,13 +556,15 @@
So far nothing new; just Python. We will integrate this code into our
Grok project now. Go to ``app.py`` and change it to read like this:
-.. include:: groktut/using_view_methods/src/sample/app.py :literal:
+.. include:: groktut/using_view_methods/src/sample/app.py
+ :literal:
We've simply added a method to our view that returns a string
representing the current date and time. Now to get this string in our
page template. Change ``index.pt`` to read like this:
-.. include:: groktut/using_view_methods/src/sample/app_templates/index.pt :literal:
+.. include:: groktut/using_view_methods/src/sample/app_templates/index.pt
+ :literal:
Restart Zope. This is needed as we changed the content of a Python
file (``app.py``). Now reload our index page to see whether it worked:
@@ -593,11 +604,13 @@
the template. Let's see how this is done. Change ``app.pt`` to read like
this:
-.. include:: groktut/generating_html_from_python/src/sample/app.py :literal:
+.. include:: groktut/generating_html_from_python/src/sample/app.py
+ :literal:
and then change ``index.pt`` to read like the following:
-.. include:: groktut/generating_html_from_python/src/sample/app_templates/index.pt :literal:
+.. include:: groktut/generating_html_from_python/src/sample/app_templates/index.pt
+ :literal:
Let's take another look at our web page:
@@ -623,7 +636,8 @@
``text/plain``. Let's change our code to return simple XML and set
the content type to ``text/xml``:
- .. include:: groktut/setting_the_content_type/src/sample/app.py :literal:
+ .. include:: groktut/setting_the_content_type/src/sample/app.py
+ :literal:
All views in Grok have a ``response`` property that you can use to
manipulate response headers.
@@ -634,7 +648,8 @@
Modify ``app.py`` so it reads like this:
-.. include:: groktut/completely_python_driven_views/src/sample/app.py :literal:
+.. include:: groktut/completely_python_driven_views/src/sample/app.py
+ :literal:
If you were to start up Zope with an ``index.pt`` template still
inside ``app_templates`` you would get an error::
@@ -670,7 +685,8 @@
You can do this by defining an ``update`` method on the view class. Modify
``app.py`` to read like this:
-.. include:: groktut/doing_some_calculation_before_viewing_a_page/src/sample/app.py :literal:
+.. include:: groktut/doing_some_calculation_before_viewing_a_page/src/sample/app.py
+ :literal:
This sets a name ``alpha`` on the view just before the template is
being displayed, so we can use it from the template. You can set as
@@ -960,7 +976,8 @@
To make this work, change edit.pt so it reads like this:
-.. include:: groktut/showing_the_value_in_the_form/src/pebbles/app_templates/edit.pt :literal:
+.. include:: groktut/showing_the_value_in_the_form/src/pebbles/app_templates/edit.pt
+ :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.
@@ -972,7 +989,8 @@
``index.pt`` so it includes a link to the edit page. To do this, we
will use the ``url`` method on the view:
-.. include:: groktut/redirection/src/pebbles/app_templates/index.pt :literal:
+.. include:: groktut/redirection/src/pebbles/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
@@ -981,7 +999,8 @@
Now let's change the edit form so that it redirects back to the
``index`` page after you press the submit button:
-.. include:: groktut/redirection/src/pebbles/app.py :literal:
+.. include:: groktut/redirection/src/pebbles/app.py
+ :literal:
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
@@ -1027,7 +1046,8 @@
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):
-.. include:: groktut/the_rules_of_persistence/src/pebbles/app.py :literal:
+.. 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
@@ -1049,7 +1069,8 @@
We change ``index.pt`` so that it displays the list:
-.. include:: groktut/the_rules_of_persistence/src/pebbles/app_templates/index.pt :literal:
+.. include:: groktut/the_rules_of_persistence/src/pebbles/app_templates/index.pt
+ :literal:
We've also changed the text of the link to the ``edit`` page to reflect
the new adding behavior of our application.
@@ -1059,7 +1080,8 @@
new quantity, instead of changing the original. There is therefore no value
to show in as the input value anymore:
-.. include:: groktut/the_rules_of_persistence/src/pebbles/app_templates/edit.pt :literal:
+.. include:: groktut/the_rules_of_persistence/src/pebbles/app_templates/edit.pt
+ :literal:
.. sidebar:: evolution
@@ -1135,7 +1157,8 @@
We can easily amend this by adding one line to the code:
-.. include:: groktut/the_rules_of_persistence2/src/pebbles/app.py :literal:
+.. include:: groktut/the_rules_of_persistence2/src/pebbles/app.py
+ :literal:
We've now told Zope that the context object has changed (because we
modified a mutable sub-object), by adding the line::
@@ -1151,7 +1174,8 @@
object in this case), and not in the view. Let's make one final
change to show what that would look like:
-.. include:: groktut/the_rules_of_persistence3/src/pebbles/app.py :literal:
+.. include:: groktut/the_rules_of_persistence3/src/pebbles/app.py
+ :literal:
As you can see, we have created a method ``addGifts`` to the model that
takes care of appending to the list and informing the ZODB about it. This
@@ -1214,7 +1238,8 @@
Here is the ``app.py`` of our new application:
-.. include:: groktut/containers/src/pebbles/app.py :literal:
+.. include:: groktut/containers/src/pebbles/app.py
+ :literal:
A second model
---------------
@@ -1268,7 +1293,8 @@
Here is the associated template for ``MammothDetails``, ``mammothdetails.pt``:
-.. include:: groktut/containers/src/pebbles/app_templates/mammothdetails.pt :literal:
+.. include:: groktut/containers/src/pebbles/app_templates/mammothdetails.pt
+ :literal:
The first section in the template (``<h2>Mammoths</h2>``)
displays a list of the items in the container. We again use
@@ -1291,7 +1317,8 @@
Finally, we have an ``index`` page for ``Mammoth``. It displays the ``Mammoth`` attributes ``name`` and ``weight``:
-.. include:: groktut/containers/src/pebbles/app_templates/mammothdetails.pt :literal:
+.. include:: groktut/containers/src/pebbles/app_templates/mammothdetails.pt
+ :literal:
Restart Zope and try this application. Call your application
``test``. Pay special attention to the URLs.
@@ -1329,7 +1356,8 @@
First let's implement the delete operation. Here is the new ``index.pt`` template::
-.. include:: groktut/containers/src/pebbles/app_templates/index.pt :literal:
+.. include:: groktut/containers/src/pebbles/app_templates/index.pt
+ :literal:
Here we have transformed the listing into a form, with one checkbox for
each mammoth. If there are no mammoths, we use ``tal:condition`` statements
@@ -1355,7 +1383,8 @@
Now let's see the changes in ``app.py``::
-.. include:: groktut/crud/src/pebbles/app.py :literal:
+.. include:: groktut/crud/src/pebbles/app.py
+ :literal:
First we implemented the ``eatMammoth`` method in the ``Pebbles`` application.
Again, we can handle the container like a regular Python dictionary, so there
@@ -1420,7 +1449,8 @@
which glues the schema defined in ``IMammoth`` to the ``Mammoth``
model. Here is the entire ``app.py`` module::
-.. include:: groktut/crud2/src/pebbles/app.py :literal:
+.. include:: groktut/crud2/src/pebbles/app.py
+ :literal:
The big gain from all the trouble of declaring the schema comes now:
the edit form is generated automatically if we define the ``Edit``
More information about the Checkins
mailing list