Author: jmorliaguet
Date: Tue Jun 20 00:35:48 2006
New Revision: 3467

Added:
   cpsskins/branches/paris-sprint-2006/browser/negotiation/namespace.py   
(contents, props changed)
   cpsskins/branches/paris-sprint-2006/browser/rendering/configure.zcml   
(contents, props changed)
Modified:
   cpsskins/branches/paris-sprint-2006/browser/negotiation/README.txt
   cpsskins/branches/paris-sprint-2006/browser/negotiation/configure.zcml
   cpsskins/branches/paris-sprint-2006/browser/negotiation/views.py
   cpsskins/branches/paris-sprint-2006/browser/rendering/viewer.py
   cpsskins/branches/paris-sprint-2006/standard/negotiation/engine.py
   cpsskins/branches/paris-sprint-2006/thememanager.py

Log:

- made the negotiation strategy non-persistent. it is now passed via:

  ++strategy++ or set during the negotiation as an attribute of the view.



Modified: cpsskins/branches/paris-sprint-2006/browser/negotiation/README.txt
==============================================================================
--- cpsskins/branches/paris-sprint-2006/browser/negotiation/README.txt  
(original)
+++ cpsskins/branches/paris-sprint-2006/browser/negotiation/README.txt  Tue Jun 
20 00:35:48 2006
@@ -49,9 +49,19 @@
 Negotiation strategy
 --------------------
 
-A negotiation *strategy* is a set of negotiation chains.
+A negotiation *strategy* is a set of negotiation chains. Each strategy has a
+unique name.
 
-Each *theme management folder* can have its own negotiation strategy.
+The name is set with a traversal adapter:
+
+  /++skin++cpsskins/++strategy++new-strategy/...
+
+or during the negotiation phase by setting the 'strategy' attribute on the
+INegotiation view:
+
+    negotiation = getMultiAdapter((context, request), INegotiation,
+                                   name='negotiation')
+    negotiation.strategy = u'new-strategy'
 
 
 Test setup:

Modified: cpsskins/branches/paris-sprint-2006/browser/negotiation/configure.zcml
==============================================================================
--- cpsskins/branches/paris-sprint-2006/browser/negotiation/configure.zcml      
(original)
+++ cpsskins/branches/paris-sprint-2006/browser/negotiation/configure.zcml      
Tue Jun 20 00:35:48 2006
@@ -1,9 +1,10 @@
 <configure
-    xmlns="http://namespaces.zope.org/browser";>
+    xmlns="http://namespaces.zope.org/zope";
+    xmlns:browser="http://namespaces.zope.org/browser";>
 
   <!-- Negotiation view -->
 
-  <view
+  <browser:view
     for="*"
     name="negotiation"
     provides=".interfaces.INegotiation"
@@ -13,4 +14,22 @@
     layer="cpsskins.browser.skin.cpsskins"
   />
 
+
+  <!-- traversal adapter for ++strategy++ -->
+
+  <adapter
+    for="*"
+    name="strategy"
+    provides="zope.traversing.interfaces.ITraversable"
+    factory=".namespace.strategy"
+  />
+
+  <view
+    for="*"
+    name="strategy"
+    type="zope.interface.Interface"
+    provides="zope.traversing.interfaces.ITraversable"
+    factory=".namespace.strategy"
+  />
+
 </configure>

Added: cpsskins/branches/paris-sprint-2006/browser/negotiation/namespace.py
==============================================================================
--- (empty file)
+++ cpsskins/branches/paris-sprint-2006/browser/negotiation/namespace.py        
Tue Jun 20 00:35:48 2006
@@ -0,0 +1,29 @@
+##############################################################################
+#
+# 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.traversing.namespace import view
+
+# ++strategy++ traverser
+class strategy(view):
+
+    def traverse(self, name, ignored):
+        self.request.annotations['cpsskins.strategy'] = name
+
+        return self.context
+

Modified: cpsskins/branches/paris-sprint-2006/browser/negotiation/views.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/browser/negotiation/views.py    
(original)
+++ cpsskins/branches/paris-sprint-2006/browser/negotiation/views.py    Tue Jun 
20 00:35:48 2006
@@ -35,16 +35,27 @@
         self.request = request
 
     def negotiate(self, name):
-        manager = getThemeManager(self.context)
-        strategy = getUtility(INegotiationStrategy, manager.negotiation)
-        chain = strategy.getChain(name)
-        negotiation_context = (self.context, manager, self.request)
+        context = self.context
+        request = self.request
+
+        manager = getThemeManager(context)
+        strategy_info = getUtility(INegotiationStrategy, self.strategy)
+        chain = strategy_info.getChain(name)
+        negotiation_context = (context, manager, request)
         for scheme in chain:
             result = getMultiAdapter(negotiation_context, scheme, name=name)()
             if result:
                 return result
         return None
 
+    def setStrategy(self, name):
+        self.request.annotations['cpsskins.strategy'] = name
+
+    def getStrategy(self):
+        return self.request.annotations.get('cpsskins.strategy', u'default')
+
+    strategy = property(getStrategy, setStrategy)
+
     ###################################################################
     # Themes and pages
     ###################################################################

Added: cpsskins/branches/paris-sprint-2006/browser/rendering/configure.zcml
==============================================================================
--- (empty file)
+++ cpsskins/branches/paris-sprint-2006/browser/rendering/configure.zcml        
Tue Jun 20 00:35:48 2006
@@ -0,0 +1,13 @@
+<configure
+    xmlns="http://namespaces.zope.org/zope";
+    xmlns:browser="http://namespaces.zope.org/browser";>
+
+  <browser:view
+      name="viewer"
+      for="cpsskins.elements.interfaces.IElement"
+      layer="cpsskins.browser.skin.cpsskins"
+      class=".viewer.Viewer"
+      permission="zope.Public"
+  />
+
+</configure>

Modified: cpsskins/branches/paris-sprint-2006/browser/rendering/viewer.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/browser/rendering/viewer.py     
(original)
+++ cpsskins/branches/paris-sprint-2006/browser/rendering/viewer.py     Tue Jun 
20 00:35:48 2006
@@ -75,6 +75,7 @@
         resources = getUtility(IResourceManager)
 
         # update global context info variables passed as keyword parameters
+        # e.g. the engine's name
         globals = ContextInfo(kw)
         globals.update({
             'request': request,
@@ -84,7 +85,7 @@
             })
 
         if globals.engine is None:
-            globals.engine = 'default'
+            globals.engine = u'default'
         globals.accesskeys = []
 
         # set the current location unless specified

Modified: cpsskins/branches/paris-sprint-2006/standard/negotiation/engine.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/standard/negotiation/engine.py  
(original)
+++ cpsskins/branches/paris-sprint-2006/standard/negotiation/engine.py  Tue Jun 
20 00:35:48 2006
@@ -28,5 +28,5 @@
     implements(IRequestNegotiationScheme)
 
     def __call__(self):
-        return self.request.annotations.get('cpsskins.engine', 'default')
+        return self.request.annotations.get('cpsskins.engine', u'default')
 

Modified: cpsskins/branches/paris-sprint-2006/thememanager.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/thememanager.py (original)
+++ cpsskins/branches/paris-sprint-2006/thememanager.py Tue Jun 20 00:35:48 2006
@@ -58,12 +58,6 @@
     The methods may be moved to other classes.
     """
 
-    negotiation = TextLine(
-        title=_(u"The negotiation strategy"),
-        description=_(u"The name of the negotiation strategy."),
-        required=False,
-        )
-
     def getSite():
         """Return the site"""
 
@@ -150,11 +144,9 @@
     """
     implements(IThemeManagementFolder, IThemeContainer)
 
-    def __init__(self, negotiation=u'default'):
+    def __init__(self):
         BTreeContainer.__init__(self)
         PersistentComponents.__init__(self)
-        # negotiation strategy
-        self.negotiation = negotiation
         # registries, storages, etc.
         self[u'uids'] = Uids()
         self[u'imagecache'] = ImageCache()
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to