Author: jmorliaguet
Date: Sat Apr  1 00:08:57 2006
New Revision: 2752

Added:
   cpsskins/branches/jmo-perspectives/browser/negotiation/plugins/page.py   
(contents, props changed)
Modified:
   cpsskins/branches/jmo-perspectives/browser/negotiation/plugins/configure.zcml
   cpsskins/branches/jmo-perspectives/browser/negotiation/plugins/theme.py
   cpsskins/branches/jmo-perspectives/browser/negotiation/views.py
Log:

- added a page negotiator



Modified: 
cpsskins/branches/jmo-perspectives/browser/negotiation/plugins/configure.zcml
==============================================================================
--- 
cpsskins/branches/jmo-perspectives/browser/negotiation/plugins/configure.zcml   
    (original)
+++ 
cpsskins/branches/jmo-perspectives/browser/negotiation/plugins/configure.zcml   
    Sat Apr  1 00:08:57 2006
@@ -9,6 +9,7 @@
       for="cpsskins.elements.interfaces.IElement
            cpsskins.interfaces.IThemeManagementFolder
            zope.publisher.interfaces.IRequest"
+      name="theme"
   />
 
   <adapter
@@ -17,6 +18,7 @@
       for="cpsskins.elements.interfaces.IElement
            cpsskins.interfaces.IThemeManagementFolder
            zope.publisher.interfaces.IRequest"
+      name="theme"
   />
 
   <adapter
@@ -25,6 +27,7 @@
       for="cpsskins.elements.interfaces.IElement
            cpsskins.interfaces.IThemeManagementFolder
            zope.publisher.interfaces.IRequest"
+      name="theme"
   />
 
   <adapter
@@ -33,6 +36,7 @@
       for="cpsskins.elements.interfaces.IElement
            cpsskins.interfaces.IThemeManagementFolder
            zope.publisher.interfaces.IRequest"
+      name="theme"
   />
 
   <adapter
@@ -41,6 +45,55 @@
       for="cpsskins.elements.interfaces.IElement
            cpsskins.interfaces.IThemeManagementFolder
            zope.publisher.interfaces.IRequest"
+      name="theme"
+  />
+
+
+  <!-- page negotiators -->
+
+  <adapter
+      factory=".page.QueryParameter"
+      provides=".interfaces.IQueryParameterNegotiator"
+      for="cpsskins.elements.interfaces.IElement
+           cpsskins.interfaces.IThemeManagementFolder
+           zope.publisher.interfaces.IRequest"
+      name="page"
+  />
+
+  <adapter
+      factory=".page.Cookie"
+      provides=".interfaces.ICookieNegotiator"
+      for="cpsskins.elements.interfaces.IElement
+           cpsskins.interfaces.IThemeManagementFolder
+           zope.publisher.interfaces.IRequest"
+      name="page"
+  />
+
+  <adapter
+      factory=".page.Local"
+      provides=".interfaces.ILocalNegotiator"
+      for="cpsskins.elements.interfaces.IElement
+           cpsskins.interfaces.IThemeManagementFolder
+           zope.publisher.interfaces.IRequest"
+      name="page"
+  />
+
+  <adapter
+      factory=".page.Default"
+      provides=".interfaces.IDefaultNegotiator"
+      for="cpsskins.elements.interfaces.IElement
+           cpsskins.interfaces.IThemeManagementFolder
+           zope.publisher.interfaces.IRequest"
+      name="page"
+  />
+
+  <adapter
+      factory=".page.Context"
+      provides=".interfaces.IContextNegotiator"
+      for="cpsskins.elements.interfaces.IElement
+           cpsskins.interfaces.IThemeManagementFolder
+           zope.publisher.interfaces.IRequest"
+      name="page"
   />
 
 
@@ -52,6 +105,7 @@
       for="cpsskins.elements.interfaces.IElement
            cpsskins.interfaces.IThemeManagementFolder
            zope.publisher.interfaces.IRequest"
+      name="perspective"
   />
 
 
@@ -63,6 +117,7 @@
       for="cpsskins.elements.interfaces.IElement
            cpsskins.interfaces.IThemeManagementFolder
            zope.publisher.interfaces.IRequest"
+      name="engine"
   />
 
 </configure>

Added: cpsskins/branches/jmo-perspectives/browser/negotiation/plugins/page.py
==============================================================================
--- (empty file)
+++ cpsskins/branches/jmo-perspectives/browser/negotiation/plugins/page.py      
Sat Apr  1 00:08:57 2006
@@ -0,0 +1,92 @@
+##############################################################################
+#
+# Copyright (c) 2005-2006 Nuxeo 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.
+#
+##############################################################################
+"""
+
+$Id$
+"""
+__docformat__ = "reStructuredText"
+
+from zope.component import queryUtility, provideUtility
+from zope.interface import implements
+
+from cpsskins.browser.negotiation.interfaces import INegotiator
+from cpsskins.browser.negotiation.interfaces import INegotiationChain
+from cpsskins.browser.negotiation.negotiator import Negotiator
+from cpsskins.browser.negotiation.plugins.interfaces import (
+    IQueryParameterNegotiator, ICookieNegotiator, ILocalNegotiator,
+    IDefaultNegotiator, IContextNegotiator)
+
+from cpsskins.elements.interfaces import IThemePage
+
+class QueryParameter(Negotiator):
+    """Look for a page whose name is passed as a URL query parameter:
+    ?theme=name
+    """
+    implements(IQueryParameterNegotiator)
+
+    def __call__(self):
+        name = self.request.form.get('page')
+        if not name:
+            return None
+        return self.manager.getPageByName(name)
+
+class Cookie(Negotiator):
+    """Look for a page whose name is stored in a cookie
+    """
+    implements(ICookieNegotiator)
+
+    def __call__(self):
+        name = self.request.cookies.get('cpsskins_work_page')
+        if not name:
+            return None
+        return self.manager.getPageByName(name)
+
+class Local(Negotiator):
+    """Look for a page located in a parent folder.
+    """
+    implements(ILocalNegotiator)
+
+    def __call__(self):
+        return queryUtility(IPage, context=self.context)
+
+class Default(Negotiator):
+    """Look for a default page
+    """
+    implements(IDefaultNegotiator)
+
+    def __call__(self):
+        return self.manager.getDefaultPage()
+
+class Context(Negotiator):
+    """Look for a page in the context
+    """
+    implements(IContextNegotiator)
+
+    def __call__(self):
+        if IThemePage.implementedBy(self.context):
+            return self.context
+        return None
+
+
+class PageNegotiationChain:
+
+    implements(INegotiationChain)
+
+    def __call__(self):
+
+        return (IQueryParameterNegotiator, ICookieNegotiator,
+                IContextNegotiator, ILocalNegotiator, IDefaultNegotiator,
+               )
+
+provideUtility(PageNegotiationChain(), INegotiationChain, 'page')

Modified: 
cpsskins/branches/jmo-perspectives/browser/negotiation/plugins/theme.py
==============================================================================
--- cpsskins/branches/jmo-perspectives/browser/negotiation/plugins/theme.py     
(original)
+++ cpsskins/branches/jmo-perspectives/browser/negotiation/plugins/theme.py     
Sat Apr  1 00:08:57 2006
@@ -74,8 +74,9 @@
     implements(IContextNegotiator)
 
     def __call__(self):
-        return ITheme.implementedBy(self.context)
-
+        if ITheme.implementedBy(self.context):
+            return self.context
+        return None
 
 class ThemeNegotiationChain:
 

Modified: cpsskins/branches/jmo-perspectives/browser/negotiation/views.py
==============================================================================
--- cpsskins/branches/jmo-perspectives/browser/negotiation/views.py     
(original)
+++ cpsskins/branches/jmo-perspectives/browser/negotiation/views.py     Sat Apr 
 1 00:08:57 2006
@@ -19,21 +19,14 @@
 
 from zope.app import zapi
 from zope.app.publisher.browser import BrowserView
-from zope.app.session.interfaces import ISession
 from zope.component import getMultiAdapter
 from zope.interface import implements
 
-from cpsskins.elements.interfaces import ITheme, IThemePage
 from cpsskins.browser.rendering.interfaces import IViewer
 from cpsskins.browser.negotiation.interfaces import INegotiation
 from cpsskins.browser.negotiation.interfaces import INegotiationChain
 from cpsskins.utils import getThemeManager
 
-from cpsskins.browser.negotiation.plugins import theme as themePlugin
-from cpsskins.browser.negotiation.plugins.interfaces import (
-    IQueryParameterNegotiator, ICookieNegotiator, ILocalNegotiator,
-    IDefaultNegotiator, IContextNegotiator)
-
 class NegotiationView(BrowserView):
     """A view for the negotiation of the effective theme, perspective, ...
     """
@@ -43,7 +36,8 @@
         chain = zapi.getUtility(interface=INegotiationChain, name=type)()
         negotiation_context = (self.context, getThemeManager(), self.request)
         for negotiator in chain:
-            result = getMultiAdapter(negotiation_context, negotiator)()
+            result = getMultiAdapter(negotiation_context,
+                                     negotiator, name=type)()
             if result:
                 return result
         return None
@@ -69,13 +63,7 @@
         """Return the effective page
         (the one that will be effectively displayed)
         """
-        context = self.context
-        # use the contextual page (e.g. in editor mode)
-        if IThemePage.providedBy(context):
-            return context
-        # use the default page of the effective theme
-        theme = self.getTheme()
-        return theme.getDefaultPage()
+        return self.negotiate('page')
 
     ###################################################################
     # Perspectives
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to