[Checkins] SVN: Sandbox/cklinger/megrok.ootbviewlets/trunk/src/megrok/ootbviewlets/ Added Readme working on tests

Christian Klinger cklinger at novareto.de
Wed Apr 1 06:56:26 EDT 2009


Log message for revision 98747:
  Added Readme working on tests

Changed:
  U   Sandbox/cklinger/megrok.ootbviewlets/trunk/src/megrok/ootbviewlets/README.txt
  U   Sandbox/cklinger/megrok.ootbviewlets/trunk/src/megrok/ootbviewlets/__init__.py
  U   Sandbox/cklinger/megrok.ootbviewlets/trunk/src/megrok/ootbviewlets/tests/test_actions.py
  A   Sandbox/cklinger/megrok.ootbviewlets/trunk/src/megrok/ootbviewlets/tests/test_base.py
  A   Sandbox/cklinger/megrok.ootbviewlets/trunk/src/megrok/ootbviewlets/tests/test_base_templates/
  A   Sandbox/cklinger/megrok.ootbviewlets/trunk/src/megrok/ootbviewlets/tests/test_base_templates/myview.pt
  U   Sandbox/cklinger/megrok.ootbviewlets/trunk/src/megrok/ootbviewlets/tests/test_contextmenuitem.py
  U   Sandbox/cklinger/megrok.ootbviewlets/trunk/src/megrok/ootbviewlets/tests/test_globalmenuitem.py
  U   Sandbox/cklinger/megrok.ootbviewlets/trunk/src/megrok/ootbviewlets/tests/test_tabs.py
  U   Sandbox/cklinger/megrok.ootbviewlets/trunk/src/megrok/ootbviewlets/viewlets.py

-=-
Modified: Sandbox/cklinger/megrok.ootbviewlets/trunk/src/megrok/ootbviewlets/README.txt
===================================================================
--- Sandbox/cklinger/megrok.ootbviewlets/trunk/src/megrok/ootbviewlets/README.txt	2009-04-01 08:00:09 UTC (rev 98746)
+++ Sandbox/cklinger/megrok.ootbviewlets/trunk/src/megrok/ootbviewlets/README.txt	2009-04-01 10:56:26 UTC (rev 98747)
@@ -1,14 +1,52 @@
-================
-A Simple DocTest
-================
+===================
+megrok.ootbviewlets
+===================
 
-Doctests work by evaluating txt documents that look like python
-interpreter sessions.  This test will pass:
+This package has some ready2use Viewlets and ViewletManagers
+for common parts of WebSites. megrok.ootbviewlets takes 
+z3c.menu.simple [1] as base. So if you want to see more in
+detail description. Please take a look in the documentation
+and tests of z3c.menu.simple.
 
-  >>> 1+1
-  2
+An example say´s more than 1000 words...
+----------------------------------------
 
-The following test will not pass (that's why it is commented out):
+class MyManager(TabMenu):
+    grok.name('mymanager')
 
-#  >>> print 'apples and bananas'
-#  oranges
\ No newline at end of file
+class MyTab(TabItem):
+    grok.name('delete')
+
+    urlEndings = ['delete', ]
+    viewURL = 'delete'
+
+If you render the MyManager you will get this output:
+
+  <div class="tabMenu">
+    <span class="inactive-menu-item">
+    <a href="http://localhost/tabs/delete">delete</a>
+  </span>
+  </div> 
+
+
+So what are common parts in a WebSite:
+--------------------------------------
+
+- ContextMenuItems
+  This Viewlet is useful if you need to create an send_to link
+  on every object. You can use a grok.ViewletManager for ContextMenuItems.
+
+- GlobalMenuItems
+  This Viewlet allows you add global Items to your site.
+  For example a logout link. You can use a grok.ViewletManager
+  for GlobalMenuItems
+
+- TabItemMenu, TabItem
+  TabItemMenu is a ViewletManager which renders TabItems in this form:
+
+- ActionItemMenu, ActionItem
+  The ViewletManager ActionItemMenu renders the ActionItems which are Viewlets
+  
+  
+
+[1] http://pypi.python.org/z3c.menu.simple

Modified: Sandbox/cklinger/megrok.ootbviewlets/trunk/src/megrok/ootbviewlets/__init__.py
===================================================================
--- Sandbox/cklinger/megrok.ootbviewlets/trunk/src/megrok/ootbviewlets/__init__.py	2009-04-01 08:00:09 UTC (rev 98746)
+++ Sandbox/cklinger/megrok.ootbviewlets/trunk/src/megrok/ootbviewlets/__init__.py	2009-04-01 10:56:26 UTC (rev 98747)
@@ -1,2 +1,2 @@
 from managers import TabMenu, ActionMenu
-from viewlets import ContextViewlet, GlobalMenuViewlet, TabItem, ActionItem
+from viewlets import ContextMenuItem, GlobalMenuItem, TabItem, ActionItem

Modified: Sandbox/cklinger/megrok.ootbviewlets/trunk/src/megrok/ootbviewlets/tests/test_actions.py
===================================================================
--- Sandbox/cklinger/megrok.ootbviewlets/trunk/src/megrok/ootbviewlets/tests/test_actions.py	2009-04-01 08:00:09 UTC (rev 98746)
+++ Sandbox/cklinger/megrok.ootbviewlets/trunk/src/megrok/ootbviewlets/tests/test_actions.py	2009-04-01 10:56:26 UTC (rev 98747)
@@ -20,7 +20,7 @@
   <div class="actionMenuWrapper">
     <ul class="actionMenu">
       <li class="inactive-menu-item">
-    <a href="">
+    <a href="http://localhost/actions/print"> 
       <div>print</div>
     </a>
   </li>

Added: Sandbox/cklinger/megrok.ootbviewlets/trunk/src/megrok/ootbviewlets/tests/test_base.py
===================================================================
--- Sandbox/cklinger/megrok.ootbviewlets/trunk/src/megrok/ootbviewlets/tests/test_base.py	                        (rev 0)
+++ Sandbox/cklinger/megrok.ootbviewlets/trunk/src/megrok/ootbviewlets/tests/test_base.py	2009-04-01 10:56:26 UTC (rev 98747)
@@ -0,0 +1,56 @@
+"""
+Set up a content object in the application root::
+
+  >>> from zope.app.testing.functional import getRootFolder
+  >>> from zope.app.component.hooks import setSite 
+  >>> root = getRootFolder()
+  >>> root['base'] = App()
+  >>> setSite(root['base'])
+
+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
+
+The GlobalMenuItem should now act as a normal grok.Viewlet.
+This means it should not return the GlobalMenuItem, it should 
+return a simple <p> tag. This demonstrates that the normal
+update render pattern, known from grok.Viewlet works
+as expected.
+
+  >>> browser.open("http://localhost/base/@@myview")
+  >>> print browser.contents
+  <p> This message was stored in the update method </p>
+"""
+import grok
+from zope.interface import Interface
+from megrok.ootbviewlets import GlobalMenuItem
+
+class App(grok.Application, grok.Container):
+    pass
+
+class MyView(grok.View):
+    pass
+
+class MyManager(grok.ViewletManager):
+    grok.name('mymanager')
+
+class CustomViewlet(GlobalMenuItem):
+
+    viewURL = 'logout.html'
+
+    def update(self):
+	self.message = "This message was stored in the update method"
+
+    def render(self):
+	return "<p> %s </p>" %self.message
+
+def test_suite():
+    from zope.testing import doctest
+    from megrok.ootbviewlets.tests import FunctionalLayer
+    suite = doctest.DocTestSuite(optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS|doctest.REPORT_NDIFF)
+    suite.layer = FunctionalLayer
+    return suite
+

Added: Sandbox/cklinger/megrok.ootbviewlets/trunk/src/megrok/ootbviewlets/tests/test_base_templates/myview.pt
===================================================================
--- Sandbox/cklinger/megrok.ootbviewlets/trunk/src/megrok/ootbviewlets/tests/test_base_templates/myview.pt	                        (rev 0)
+++ Sandbox/cklinger/megrok.ootbviewlets/trunk/src/megrok/ootbviewlets/tests/test_base_templates/myview.pt	2009-04-01 10:56:26 UTC (rev 98747)
@@ -0,0 +1 @@
+<span tal:replace="structure provider:mymanager" />

Modified: Sandbox/cklinger/megrok.ootbviewlets/trunk/src/megrok/ootbviewlets/tests/test_contextmenuitem.py
===================================================================
--- Sandbox/cklinger/megrok.ootbviewlets/trunk/src/megrok/ootbviewlets/tests/test_contextmenuitem.py	2009-04-01 08:00:09 UTC (rev 98746)
+++ Sandbox/cklinger/megrok.ootbviewlets/trunk/src/megrok/ootbviewlets/tests/test_contextmenuitem.py	2009-04-01 10:56:26 UTC (rev 98747)
@@ -18,27 +18,24 @@
 
   >>> browser.open("http://localhost/fred/@@myview")
   >>> print browser.contents
-  <a href="http://localhost/fred/print"
-     class="inactive-menu-item">printviewlet</a>
+  <a href="http://localhost/fred/print" class="myInActiveCss">printviewlet</a>
 
 Now look if we get the right link in the context of klaus too
 
   >>> browser.open("http://localhost/klaus/@@myview")
   >>> print browser.contents
-  <a href="http://localhost/klaus/print"
-     class="inactive-menu-item">printviewlet</a>
+  <a href="http://localhost/klaus/print" class="myInActiveCss">printviewlet</a>
 
 Now check if we get the right css class if we had the same url
 endings in our view and the urlEndings in our Viewlet
 
   >>> browser.open("http://localhost/klaus/@@print")
   >>> print browser.contents
-  <a href="http://localhost/klaus/print"
-     class="active-menu-item">printviewlet</a>
+  <a href="http://localhost/klaus/print" class="myCustomCss">printviewlet</a>
 
 """
 import grok
-from megrok.ootbviewlets import ContextViewlet
+from megrok.ootbviewlets import ContextMenuItem
 
 class MyContext(grok.Context):
     pass
@@ -52,14 +49,13 @@
 class MyManager(grok.ViewletManager):
     grok.name('mymanager')
 
-class PrintViewlet(ContextViewlet):
-
+class PrintViewlet(ContextMenuItem):
     urlEndings = ['print', ]
     viewURL = 'print'
+    activeCSS = u'myCustomCss'
+    inActiveCSS = u'myInActiveCss'
 
 
-
-
 def test_suite():
     from zope.testing import doctest
     from megrok.ootbviewlets.tests import FunctionalLayer

Modified: Sandbox/cklinger/megrok.ootbviewlets/trunk/src/megrok/ootbviewlets/tests/test_globalmenuitem.py
===================================================================
--- Sandbox/cklinger/megrok.ootbviewlets/trunk/src/megrok/ootbviewlets/tests/test_globalmenuitem.py	2009-04-01 08:00:09 UTC (rev 98746)
+++ Sandbox/cklinger/megrok.ootbviewlets/trunk/src/megrok/ootbviewlets/tests/test_globalmenuitem.py	2009-04-01 10:56:26 UTC (rev 98747)
@@ -31,7 +31,7 @@
 """
 import grok
 from zope.interface import Interface
-from megrok.ootbviewlets import GlobalMenuViewlet
+from megrok.ootbviewlets import GlobalMenuItem
 
 class MyApp(grok.Application, grok.Container):
     pass
@@ -47,14 +47,12 @@
     grok.context(Interface)
     grok.name('mymanager')
 
-class LogoutViewlet(GlobalMenuViewlet):
+class LogoutViewlet(GlobalMenuItem):
     grok.context(Interface)
 
     viewURL = 'logout.html'
 
 
-
-
 def test_suite():
     from zope.testing import doctest
     from megrok.ootbviewlets.tests import FunctionalLayer

Modified: Sandbox/cklinger/megrok.ootbviewlets/trunk/src/megrok/ootbviewlets/tests/test_tabs.py
===================================================================
--- Sandbox/cklinger/megrok.ootbviewlets/trunk/src/megrok/ootbviewlets/tests/test_tabs.py	2009-04-01 08:00:09 UTC (rev 98746)
+++ Sandbox/cklinger/megrok.ootbviewlets/trunk/src/megrok/ootbviewlets/tests/test_tabs.py	2009-04-01 10:56:26 UTC (rev 98747)
@@ -19,7 +19,7 @@
   >>> print browser.contents
   <div class="tabMenu">
     <span class="inactive-menu-item">
-    <a href="">print</a>
+    <a href="http://localhost/tabs/delete">delete</a>
   </span>
   <BLANKLINE>
   </div> 
@@ -37,10 +37,10 @@
     grok.name('mymanager')
 
 class MyTab(TabItem):
-    grok.name('print')
+    grok.name('delete')
 
-    urlEndings = ['print', ]
-    viewURL = 'print'
+    urlEndings = ['delete', ]
+    viewURL = 'delete'
 
 def test_suite():
     from zope.testing import doctest

Modified: Sandbox/cklinger/megrok.ootbviewlets/trunk/src/megrok/ootbviewlets/viewlets.py
===================================================================
--- Sandbox/cklinger/megrok.ootbviewlets/trunk/src/megrok/ootbviewlets/viewlets.py	2009-04-01 08:00:09 UTC (rev 98746)
+++ Sandbox/cklinger/megrok.ootbviewlets/trunk/src/megrok/ootbviewlets/viewlets.py	2009-04-01 10:56:26 UTC (rev 98747)
@@ -1,14 +1,15 @@
 import grok
+from zope.app.zapi import absoluteURL
 from z3c.menu.simple.menu import (ContextMenuItem, GlobalMenuItem,
                TabItem, ActionItem)
 
-class ContextViewlet(ContextMenuItem, grok.Viewlet):
+class ContextMenuItem(ContextMenuItem, grok.Viewlet):
     """ Viewlet based on a specific context 
     """
     grok.baseclass()
 
 
-class GlobalMenuViewlet(GlobalMenuItem, grok.Viewlet):
+class GlobalMenuItem(GlobalMenuItem, grok.Viewlet):
     """Viewlet based on a specific site
     """
     grok.baseclass()
@@ -19,6 +20,11 @@
     """
     grok.baseclass()
 
+    @property
+    def url(self):
+        contextURL = absoluteURL(self.context, self.request)
+        return contextURL + '/' + self.viewURL
+
     def render(self):
         return self.template()
 
@@ -28,6 +34,11 @@
     """
     grok.baseclass()
 
+    @property
+    def url(self):
+        contextURL = absoluteURL(self.context, self.request)
+        return contextURL + '/' + self.viewURL
+
     def render(self):
         return self.template()
 



More information about the Checkins mailing list