[Checkins] SVN: grokcore.view/branches/reinout-christian-codeview/README.txt updated readme to reflect the View/CodeView split

Reinout van Rees reinout at vanrees.org
Sat Jul 4 05:45:07 EDT 2009


Log message for revision 101485:
  updated readme to reflect the View/CodeView split
  

Changed:
  U   grokcore.view/branches/reinout-christian-codeview/README.txt

-=-
Modified: grokcore.view/branches/reinout-christian-codeview/README.txt
===================================================================
--- grokcore.view/branches/reinout-christian-codeview/README.txt	2009-07-04 09:31:25 UTC (rev 101484)
+++ grokcore.view/branches/reinout-christian-codeview/README.txt	2009-07-04 09:45:07 UTC (rev 101485)
@@ -29,20 +29,32 @@
 ``grokcore.view.View`` baseclass.  At a minimum, a browser page must
 have
 
-1. either an associated template or a ``render()`` method
+1. an associated template (for a render() method, use CodeView)
 
 2. a context that it's registered for as a view
 
 3. a name (which is, if not specified explicitly, the class's name in
    lower case characters).
 
+A browser page that does not use a template but just outputs some computed
+data should subclass ``grokcore.view.CodeView``.  At a minimum, such a view
+must have
+
+1. a render() method
+
+2. a context that it's registered for as a view
+
+3. a name (which is, if not specified explicitly, the class's name in
+   lower case characters).
+
+
 For example, the following class defines a view that's registered for
-all objects and simply prints "Hello World!"::
+all objects and simply prints "Hello World!".  This is done with a CodeView::
 
   import grokcore.view
   import zope.interface
 
-  class Hello(grokcore.view.View):
+  class Hello(grokcore.view.CodeView):
       grokcore.view.context(zope.interface.Interface)
 
       def render(self):
@@ -83,6 +95,15 @@
 
 This will greet a logged in user with his or her actual name.
 
+Such a template-using page is a subclass of ``grokcore.view.View``.
+
+  import grokcore.view
+  import zope.interface
+
+  class Hello(grokcore.view.View):
+      grokcore.view.context(zope.interface.Interface)
+
+
 To associate the template with the view, we have to put it in a
 certain place.  Let's say the ``Hello`` view class from above was in
 an ``app.py`` module.  Then we create an ``app_templates`` directory
@@ -174,6 +195,14 @@
     associated with the view as well as the ``layer`` directive to
     specify which layer it should be on if not the default layer.
 
+``CodeView``
+    Base class for browser pages.  Use the ``context`` directive to specify
+    the view's context.  Use the ``name`` directive to set the view's name; if
+    not used, the view's name will be the class's name in lower case
+    characters.  The ``layer`` directive specifies which layer it should be on
+    if not the default layer.
+
+
 View API
 --------
 
@@ -214,7 +243,7 @@
     Optionally, ``data`` can be a dictionary whose contents is added to
     the URL as a query string.
 
-Methods for developers to implement:
+Method for developers to implement:
 
 ``update(**kw)``
     This method will be called before the view's associated template
@@ -224,13 +253,15 @@
     ``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.
 
+The CodeView class can have abovementioned ``update()`` method and
+additionally *has* to implement ``render()``
 
+``render(**kw)`` 
+    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
 ----------
 
@@ -244,7 +275,7 @@
     Class-level directive that specifies the name a template file
     that's associated with a view class, *without* the file extension.
     If not used, it defaults to the class's name in lower case
-    characters.
+    characters.  Only used for View, not CodeView.
 
 ``layer(layer_interface)``
     Class-level directive that defines which layer the view is



More information about the Checkins mailing list