[Checkins] SVN: five.grok/trunk/ Fix a broken test (url method). Define a IFiveGrokAPI.

Sylvain Viollon sylvain at infrae.com
Thu Sep 17 06:02:51 EDT 2009


Log message for revision 104194:
  Fix a broken test (url method). Define a IFiveGrokAPI.
  
  

Changed:
  U   five.grok/trunk/docs/HISTORY.txt
  U   five.grok/trunk/src/five/grok/__init__.py
  A   five.grok/trunk/src/five/grok/absoluteurl.py
  U   five.grok/trunk/src/five/grok/components.py
  U   five.grok/trunk/src/five/grok/configure.zcml
  U   five.grok/trunk/src/five/grok/ftests/view/index.py
  U   five.grok/trunk/src/five/grok/ftests/view/view.py
  A   five.grok/trunk/src/five/grok/interfaces.py
  U   five.grok/trunk/src/five/grok/tests/annotation.py

-=-
Modified: five.grok/trunk/docs/HISTORY.txt
===================================================================
--- five.grok/trunk/docs/HISTORY.txt	2009-09-17 09:46:32 UTC (rev 104193)
+++ five.grok/trunk/docs/HISTORY.txt	2009-09-17 10:02:51 UTC (rev 104194)
@@ -4,6 +4,10 @@
 1.0b3 (unreleased)
 ------------------
 
+- Define an IFiveGrokAPI. [thefunny42]
+
+- Fix the broken ``url`` method on views. [thefunny42]
+
 - Reverted the CodeView stuff, see grokcore.view changelog for more details.
 
   ``CodeView`` is still available as a backwards compatibility alias

Modified: five.grok/trunk/src/five/grok/__init__.py
===================================================================
--- five.grok/trunk/src/five/grok/__init__.py	2009-09-17 09:46:32 UTC (rev 104193)
+++ five.grok/trunk/src/five/grok/__init__.py	2009-09-17 10:02:51 UTC (rev 104194)
@@ -30,13 +30,13 @@
 # please start using grokcore.view.View again.
 CodeView = View
 
-# Temporary import explicitly path from grokcore.view (it was missing
-# in its API interface)
-from grokcore.view import path
-
 # Override the one from grokcore.view so that we get Zope 2 semantics
 from five.grok.components import ZopeTwoPageTemplate as PageTemplate
 from five.grok.components import ZopeTwoPageTemplateFile as PageTemplateFile
 
 # Override DirectoryResource to use Zope 2 one
 from five.grok.components import ZopeTwoDirectoryResource as DirectoryResource
+
+# Only export public API
+from five.grok.interfaces import IFiveGrokAPI
+__all__ = list(IFiveGrokAPI)

Added: five.grok/trunk/src/five/grok/absoluteurl.py
===================================================================
--- five.grok/trunk/src/five/grok/absoluteurl.py	                        (rev 0)
+++ five.grok/trunk/src/five/grok/absoluteurl.py	2009-09-17 10:02:51 UTC (rev 104194)
@@ -0,0 +1,47 @@
+#############################################################################
+#
+# Copyright (c) 2009 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+
+from zope.traversing.browser import absoluteurl
+from zope.traversing.browser.interfaces import IAbsoluteURL
+from zope.publisher.interfaces.browser import IBrowserRequest
+
+from five.grok.interfaces import IFiveGrokView
+
+from Acquisition import aq_parent, aq_inner
+
+from zope import component
+from grokcore import component as grok
+
+
+class ViewAbsoluteURL(absoluteurl.AbsoluteURL, grok.MultiAdapter):
+
+    grok.adapts(IFiveGrokView, IBrowserRequest)
+    grok.provides(IAbsoluteURL)
+
+    def _obj(self):
+        return aq_inner(self.context.context)
+
+    def __str__(self):
+        return self._obj().absolute_url() + '/' + self.context.__view_name__
+
+    __call__ = __str__
+
+    def breadcrumbs(self):
+        obj_breadcrumbs = component.getMultiAdapter(
+            (self._obj(), self.request), IAbsoluteURL).breadcrumbs()
+
+        obj_breadcrumbs += ({'name': self.context.__view_name__,
+                                'url': self()},)
+
+        return obj_breadcrumbs

Modified: five.grok/trunk/src/five/grok/components.py
===================================================================
--- five.grok/trunk/src/five/grok/components.py	2009-09-17 09:46:32 UTC (rev 104193)
+++ five.grok/trunk/src/five/grok/components.py	2009-09-17 10:02:51 UTC (rev 104194)
@@ -34,6 +34,8 @@
 import grokcore.view
 import grokcore.security
 
+from five.grok.interfaces import IFiveGrokView
+
 from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile \
     as BaseViewPageTemplateFile
 from Products.Five.browser.pagetemplatefile import getEngine
@@ -52,7 +54,13 @@
 class Model(SimpleItem):
     interface.implements(IAttributeAnnotatable, IContext)
 
+    def __init__(self, id):
+        self._id = id
 
+    def getId(self):
+        return self._id
+
+
 class Container(Folder):
     interface.implements(IAttributeAnnotatable, IContext)
 
@@ -67,6 +75,8 @@
 
 class View(grokcore.view.View, Acquisition.Explicit):
 
+    interface.implements(IFiveGrokView)
+
     def __init__(self, *args):
         super(View, self).__init__(*args)
         if not (self.static is None):
@@ -78,10 +88,8 @@
     # We let getPhysicalPath to be acquired. This make static URL's
     # work, and prevent us to inherit from Acquisition.Implicit
     getPhysicalPath = Acquisition.Acquired
-    # We need absolute_url method to be acquired, it's used by AbsoluteURL adapter
-    # in Products/Five/browser/absoluteurl.py
-    absolute_url = Acquisition.Acquired
 
+
 # TODO: This should probably move to Products.Five.browser
 
 class ViewAwareZopePageTemplate(ZopePageTemplate):

Modified: five.grok/trunk/src/five/grok/configure.zcml
===================================================================
--- five.grok/trunk/src/five/grok/configure.zcml	2009-09-17 09:46:32 UTC (rev 104193)
+++ five.grok/trunk/src/five/grok/configure.zcml	2009-09-17 10:02:51 UTC (rev 104194)
@@ -13,6 +13,8 @@
   <include package="grokcore.viewlet" />
 
   <grok:grok package=".subscribers" />
+  <grok:grok package=".absoluteurl" />
+
   <utility component=".meta.setupUtility" />
 
   <browser:defaultView

Modified: five.grok/trunk/src/five/grok/ftests/view/index.py
===================================================================
--- five.grok/trunk/src/five/grok/ftests/view/index.py	2009-09-17 09:46:32 UTC (rev 104193)
+++ five.grok/trunk/src/five/grok/ftests/view/index.py	2009-09-17 10:02:51 UTC (rev 104194)
@@ -1,7 +1,7 @@
 """
   >>> from five.grok.ftests.view.index import *
   >>> root_folder = getRootFolder()
-  >>> mammoth = Mammoth(id='manfred')
+  >>> mammoth = Mammoth('manfred')
   >>> id = root_folder._setObject("manfred", mammoth)
 
 The default view name for a model is 'index':

Modified: five.grok/trunk/src/five/grok/ftests/view/view.py
===================================================================
--- five.grok/trunk/src/five/grok/ftests/view/view.py	2009-09-17 09:46:32 UTC (rev 104193)
+++ five.grok/trunk/src/five/grok/ftests/view/view.py	2009-09-17 10:02:51 UTC (rev 104194)
@@ -17,19 +17,15 @@
 from five import grok
 
 class Mammoth(grok.Model):
+    pass
 
-    def __init__(self, id):
-        super(Mammoth, self).__init__(id=id)
-        self.id = id
-
-
 class Painting(grok.View):
     pass
 
 painting = grok.PageTemplate("""\
 <html>
 <body>
-<h1>Hello, world <tal:replace tal:replace="here/id" />!</h1>
+<h1>Hello, world <tal:replace tal:replace="here/getId" />!</h1>
 </body>
 </html>
 """)

Added: five.grok/trunk/src/five/grok/interfaces.py
===================================================================
--- five.grok/trunk/src/five/grok/interfaces.py	                        (rev 0)
+++ five.grok/trunk/src/five/grok/interfaces.py	2009-09-17 10:02:51 UTC (rev 104194)
@@ -0,0 +1,38 @@
+#############################################################################
+#
+# Copyright (c) 2009 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+
+import grokcore.annotation.interfaces
+import grokcore.component.interfaces
+import grokcore.security.interfaces
+import grokcore.site.interfaces
+import grokcore.view.interfaces
+import grokcore.viewlet.interfaces
+import grokcore.formlib.interfaces
+
+
+class IFiveGrokView(grokcore.view.interfaces.IGrokView):
+    """A five.grok view is a specific implementation of a
+    grokcore.view.View.
+    """
+
+
+class IFiveGrokAPI(grokcore.annotation.interfaces.IGrokcoreAnnotationAPI,
+                   grokcore.component.interfaces.IGrokcoreComponentAPI,
+                   grokcore.security.interfaces.IGrokcoreSecurityAPI,
+                   grokcore.site.interfaces.IGrokcoreSiteAPI,
+                   grokcore.view.interfaces.IGrokcoreViewAPI,
+                   grokcore.viewlet.interfaces.IGrokcoreViewletAPI,
+                   grokcore.formlib.interfaces.IGrokcoreFormlibAPI):
+    """Official five.grok API.
+    """

Modified: five.grok/trunk/src/five/grok/tests/annotation.py
===================================================================
--- five.grok/trunk/src/five/grok/tests/annotation.py	2009-09-17 09:46:32 UTC (rev 104193)
+++ five.grok/trunk/src/five/grok/tests/annotation.py	2009-09-17 10:02:51 UTC (rev 104194)
@@ -7,7 +7,7 @@
 We can adapt a model to an annotation interface and obtain a
 persistent annotation storage:
 
-  >>> manfred = Mammoth()
+  >>> manfred = Mammoth('manfred')
   >>> branding = IBranding(manfred)
   >>> branding.addBrand('mine')
   >>> branding.addBrand('yours')



More information about the checkins mailing list