[Checkins] SVN: grok/trunk/doc/ Second phase of 'a view for a
model'.
Martijn Faassen
faassen at infrae.com
Sat Mar 17 07:04:29 EDT 2007
Log message for revision 73281:
Second phase of 'a view for a model'.
Changed:
A grok/trunk/doc/groktut/a_view_for_a_model2/
U grok/trunk/doc/groktut/a_view_for_a_model2/src/sample/app.py
U grok/trunk/doc/groktut/a_view_for_a_model2/src/sample/app_templates/index.pt
U grok/trunk/doc/tutorial.txt
-=-
Copied: grok/trunk/doc/groktut/a_view_for_a_model2 (from rev 73280, grok/trunk/doc/groktut/a_view_for_a_model)
Modified: grok/trunk/doc/groktut/a_view_for_a_model2/src/sample/app.py
===================================================================
--- grok/trunk/doc/groktut/a_view_for_a_model/src/sample/app.py 2007-03-17 10:58:26 UTC (rev 73280)
+++ grok/trunk/doc/groktut/a_view_for_a_model2/src/sample/app.py 2007-03-17 11:04:28 UTC (rev 73281)
@@ -5,4 +5,5 @@
return "This is important information!"
class Index(grok.View):
- pass
+ def reversed_information(self):
+ return ''.join(reversed(self.context.information()))
Modified: grok/trunk/doc/groktut/a_view_for_a_model2/src/sample/app_templates/index.pt
===================================================================
--- grok/trunk/doc/groktut/a_view_for_a_model/src/sample/app_templates/index.pt 2007-03-17 10:58:26 UTC (rev 73280)
+++ grok/trunk/doc/groktut/a_view_for_a_model2/src/sample/app_templates/index.pt 2007-03-17 11:04:28 UTC (rev 73281)
@@ -1,5 +1,10 @@
<html>
<body>
-<p tal:content="python:context.information()">replaced</p>
+<p>The information:
+ <span tal:content="python:context.information()">info</span>
+</p>
+<p>The information, reversed:
+ <span tal:replace="python:view.reversed_information()">info</span>
+</p>
</body>
</html>
Modified: grok/trunk/doc/tutorial.txt
===================================================================
--- grok/trunk/doc/tutorial.txt 2007-03-17 10:58:26 UTC (rev 73280)
+++ grok/trunk/doc/tutorial.txt 2007-03-17 11:04:28 UTC (rev 73281)
@@ -780,27 +780,23 @@
concept in structuring applications. The view, along with the
template, is responsible for displaying the information and its user
interface. The model represents the actual information the application
-is about, such as documents, blog entries or wiki pages.
+is about, such as documents, blog entries or wiki pages. The model
+should not know anything about the way it is displayed.
-Because grok structures applications this way, the way the model is
-displayed can be changed without modifying the model itself.
+This way of structuring your applications allows you to change the way
+your content is displayed without modifying the content itself, just
+the way it is viewed.
Let's do that by making the view do something to the information. Change
-``app.py`` again::
+``app.py`` again:
- import grok
+.. include:: groktut/a_view_for_a_model2/src/sample/app.py
+ :literal:
- class Sample(grok.Application, grok.Container):
- def information(self):
- return "This is important information!"
-
- class Index(grok.View):
- def reversed_information(self):
- return ''.join(reversed(self.context.information()))
-
You can see that it is possible to access the context object (an
instance of ``Sample``) from within the view class, by accessing the
-``context`` attribute.
+``context`` attribute. This gets the same object as when we used the
+``context`` name in our template before.
What we do here is reverse the string returned from the
``information()`` method. You can try it on the Python prompt::
@@ -809,18 +805,10 @@
'oof'
Now let's modify the ``index.pt`` template so that it uses the
-``reversed_information`` method::
+``reversed_information`` method:
- <html>
- <body>
- <p>The information:
- <span tal:replace="python:context.information()">info</span>
- </p>
- <p>The information, reversed:
- <span tal:replace="python:view.reversed_information()">info</span>
- </p>
- </body>
- </html>
+.. include:: groktut/a_view_for_a_model2/src/sample/app_templates/index.pt
+ :literal:
Restart Zope. When you view the page:
More information about the Checkins
mailing list