[Checkins] SVN: grokcore.view/trunk/README.txt More docs
Philipp von Weitershausen
philikon at philikon.de
Sun Aug 3 18:17:26 EDT 2008
Log message for revision 89322:
More docs
Changed:
U grokcore.view/trunk/README.txt
-=-
Modified: grokcore.view/trunk/README.txt
===================================================================
--- grokcore.view/trunk/README.txt 2008-08-03 21:59:57 UTC (rev 89321)
+++ grokcore.view/trunk/README.txt 2008-08-03 22:17:25 UTC (rev 89322)
@@ -22,8 +22,8 @@
Examples
========
-Browser page
-------------
+Simple browser page
+-------------------
A browser page is implemented by subclassing the
``grokcore.view.View`` baseclass. At a minimum, a browser page must
@@ -63,6 +63,9 @@
...
+Browser page with template
+--------------------------
+
Of course, more than often a view should render HTML which you would
construct using some sort of templating engine. ``grokcore.view``
comes with built-in support for Zope's PageTemplate engine. By
@@ -111,7 +114,15 @@
class IGreenSkin(IGreenLayer, grokcore.view.IDefaultBrowserLayer):
grokcore.view.skin('Green')
+To place a view on a layer, simply use the ``layer`` directive::
+ class Hello(grokcore.view.View):
+ grokcore.view.context(zope.interface.Interface)
+ grokcore.view.layer(IGreenLayer)
+
+ ...
+
+
API overview
============
@@ -127,6 +138,62 @@
associated with the view as well as the ``layer`` directive to
specify which layer it should be on if not the default layer.
+View API
+--------
+
+``grokcore.view.View`` is a regular Zope browser page, so it behaves
+exactly like a regular browser page from the outside. It provides a
+bit more to the developer using it as a base class, though:
+
+``context``
+ The view's context object. This can be discriminated by using the
+ ``context`` directive on the view class.
+
+``request``
+ The request object, typically provides ``IBrowserRequest``.
+
+``response``
+ The response object, typically provides ``IHTTPResponse``.
+
+``static``
+ Directory resource representing the package's ``static`` directory.
+
+``redirect(url)``
+ Redirect to the given URL.
+
+``url(obj=None, name=None, data=None)``
+ Constructs a URL:
+
+ * If no arguments are given, the URL to the view itself is
+ constructed.
+
+ * If only the ``obj`` argument is given, the URL to that object is
+ constructed.
+
+ * If both ``obj`` and ``name`` arguments are supplied, construct
+ the URL to the object and append ``name`` (presumably the name
+ of a view).
+
+ Optionally, ``data`` can be a dictionary whose contents is added to
+ the URL as a query string.
+
+Methods for developers to implement:
+
+``update(**kw)``
+ This method will be called before the view's associated template
+ is rendered. If you therefore want to pre-compuate values for the
+ template, implement this method. You can save the values on
+ ``self`` (the view object) and later access them through the
+ ``view`` variable from the template. The method can take
+ arbitrary keyword parameters which are filled from request values.
+
+``render(**kw)``
+ Implement this method if (and only if) there isn't a template that
+ goes with the view class. Return either an encoded 8-bit string
+ or a unicode string. The method can take arbitrary keyword
+ parameters which are filled from request values.
+
+
Directives
----------
More information about the Checkins
mailing list