Author: jmorliaguet Date: Fri Mar 31 23:23:58 2006 New Revision: 2750 Added: cpsskins/branches/jmo-perspectives/browser/negotiation/plugins/perspective.py (contents, props changed) Modified: cpsskins/branches/jmo-perspectives/browser/negotiation/plugins/configure.zcml cpsskins/branches/jmo-perspectives/browser/negotiation/plugins/interfaces.py cpsskins/branches/jmo-perspectives/browser/negotiation/views.py Log:
- added a negotiation chain for perspectives. - declared a session-based negotiator interface (ISessionNegotiator) 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 Fri Mar 31 23:23:58 2006 @@ -44,4 +44,15 @@ /> + <!-- perspective negotiators --> + + <adapter + factory=".perspective.Session" + provides=".interfaces.ISessionNegotiator" + for="cpsskins.elements.interfaces.IElement + cpsskins.interfaces.IThemeManagementFolder + zope.publisher.interfaces.IRequest" + /> + + </configure> Modified: cpsskins/branches/jmo-perspectives/browser/negotiation/plugins/interfaces.py ============================================================================== --- cpsskins/branches/jmo-perspectives/browser/negotiation/plugins/interfaces.py (original) +++ cpsskins/branches/jmo-perspectives/browser/negotiation/plugins/interfaces.py Fri Mar 31 23:23:58 2006 @@ -29,6 +29,10 @@ """Cookie-based negotiation. """ +class ISessionNegotiator(INegotiator): + """Session-based negotiation. + """ + class ILocalNegotiator(INegotiator): """Local negotiation. """ Added: cpsskins/branches/jmo-perspectives/browser/negotiation/plugins/perspective.py ============================================================================== --- (empty file) +++ cpsskins/branches/jmo-perspectives/browser/negotiation/plugins/perspective.py Fri Mar 31 23:23:58 2006 @@ -0,0 +1,50 @@ +############################################################################## +# +# 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.app.session.interfaces import ISession +from zope.component import provideUtility +from zope.interface import implements + +from cpsskins.browser.negotiation.interfaces import INegotiationChain +from cpsskins.browser.negotiation.negotiator import Negotiator +from cpsskins.browser.negotiation.plugins.interfaces import ISessionNegotiator + +class Session(Negotiator): + """Look for a perspective in the session. + """ + implements(ISessionNegotiator) + + def __call__(self): + pkg_id = 'cpsskins' + session = ISession(self.request)[pkg_id] + try: + perspective = session['perspective'] + except KeyError: + perspective = None + return perspective + +class PerspectiveNegotiationChain: + + implements(INegotiationChain) + + def __call__(self): + + return (ISessionNegotiator, ) + +provideUtility(PerspectiveNegotiationChain(), INegotiationChain, 'perspective') 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 Fri Mar 31 23:23:58 2006 @@ -82,13 +82,7 @@ ################################################################### def getPerspective(self): - pkg_id = 'cpsskins' - session = ISession(self.request)[pkg_id] - try: - perspective = session['perspective'] - except KeyError: - perspective = None - return perspective + return self.negotiate('perspective') ################################################################### # Engines -- http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins