[Checkins] SVN: grok/branches/snowsprint-viewlets/src/grok/ftests/viewlet/viewlet_security.py Fixed so viewlets work good with layers.

Tim Terlegård tim.terlegard at valentinewebsystems.se
Tue Jan 22 10:28:11 EST 2008


Log message for revision 83089:
  Fixed so viewlets work good with layers.
  

Changed:
  U   grok/branches/snowsprint-viewlets/src/grok/ftests/viewlet/viewlet_security.py

-=-
Modified: grok/branches/snowsprint-viewlets/src/grok/ftests/viewlet/viewlet_security.py
===================================================================
--- grok/branches/snowsprint-viewlets/src/grok/ftests/viewlet/viewlet_security.py	2008-01-22 14:40:52 UTC (rev 83088)
+++ grok/branches/snowsprint-viewlets/src/grok/ftests/viewlet/viewlet_security.py	2008-01-22 15:28:11 UTC (rev 83089)
@@ -1,10 +1,21 @@
 """
 
+=============
 Test Viewlets
 =============
 
+This doctest will test the various grok viewlet registrations. Grok
+viewlets offer the same flexibility as zope3, allowing you to register
+viewlets for a particular view, context, layer, and permission.
+
+Set up a content object in the application root::
+
   >>> root = getRootFolder()
   >>> root['wilma'] = CaveWoman()
+
+Traverse to the view on the model object. We get the viewlets
+registered for the default layer, with the anybody permission::
+
   >>> from zope.testbrowser.testing import Browser
   >>> browser = Browser()
   >>> browser.handleErrors = False
@@ -13,6 +24,10 @@
   Brack Bone
   T-Rex Bone
 
+After assigning the ``grok.BoneOwner`` role to ``zope.anybody``, he
+gains the ``bone.gold`` permission. This allows the principal to view
+the ``GoldBone`` viewlet::
+
   >>> from zope.securitypolicy.interfaces import IPrincipalRoleManager
   >>> IPrincipalRoleManager(root).assignRoleToPrincipal(
   ...    'grok.BoneOwner', 'zope.anybody')
@@ -22,14 +37,20 @@
   Gold Bone
   T-Rex Bone
 
-  >> browser.open('http://localhost/++skin++boneskin/wilma/@@caveview')
-  >> print browser.contents
+Now we traverse to the view through a skin. Now we gain the viewlet registered for a particular layer, ``LayeredBone``::
+
+  >>> browser.open('http://localhost/++skin++boneskin/wilma/@@caveview')
+  >>> print browser.contents
+  Brack Bone
+  Gold Bone
   Layered Bone
+  T-Rex Bone
 
 """
 
 
 import grok
+from zope.publisher.interfaces.browser import IDefaultBrowserLayer
 
 
 class Gold(grok.Permission):
@@ -68,7 +89,7 @@
     def render(self):
         return 'Gold Bone'
 
-class IBoneLayer(grok.IGrokLayer):
+class IBoneLayer(grok.IGrokLayer, IDefaultBrowserLayer):
     pass
 
 class LayeredBone(grok.Viewlet):



More information about the Checkins mailing list