[CMF-checkins] CVS: CMF/CMFCore - Skinnable.py:1.7 SkinsContainer.py:1.6
Shane Hathaway
shane@cvs.zope.org
Thu, 22 Aug 2002 13:45:53 -0400
Update of /cvs-repository/CMF/CMFCore
In directory cvs.zope.org:/tmp/cvs-serv15832
Modified Files:
Skinnable.py SkinsContainer.py
Log Message:
Merged runyaga's skinnable changes: there is now a changeSkin() method on
the portal object. Use it to change skins mid-request. Note that this
has always been possible to do, but not fully supported.
Also moved getSkin() from SkinsContainer to Skinnable to simplify the
implementation of changeSkin(), and updated the portal_skins tool interface.
=== CMF/CMFCore/Skinnable.py 1.6 => 1.7 ===
--- CMF/CMFCore/Skinnable.py:1.6 Thu Aug 1 15:05:11 2002
+++ CMF/CMFCore/Skinnable.py Thu Aug 22 13:45:53 2002
@@ -72,6 +72,41 @@
raise AttributeError, name
return superGetAttr(self, name)
+ security.declarePrivate('getSkin')
+ def getSkin(self, name=None):
+ """Returns the requested skin.
+ """
+ skinob = None
+ skinstool = None
+ sfn = self.getSkinsFolderName()
+
+ if sfn is not None:
+ sf = getattr(self, sfn, None)
+ if sf is not None:
+ if name is not None:
+ skinob = sf.getSkinByName(name)
+ if skinob is None:
+ skinob = sf.getSkinByName(sf.getDefaultSkin())
+ if skinob is None:
+ skinob = sf.getSkinByPath('')
+ return skinob
+
+ security.declarePublic('getSkinNameFromRequest')
+ def getSkinNameFromRequest(self, REQUEST=None):
+ ''' returns the skin name from the Request'''
+ sfn = self.getSkinsFolderName()
+ if sfn is not None:
+ sf = getattr(self, sfn, None)
+ if sf is not None:
+ return REQUEST.get(sf.getRequestVarname(), None)
+
+ security.declarePublic('changeSkin')
+ def changeSkin(self, skinname):
+ self._v_skindata = None
+ skinobj = self.getSkin(skinname)
+ if skinobj is not None:
+ self._v_skindata = (self.REQUEST, skinobj, {})
+
security.declarePublic('setupCurrentSkin')
def setupCurrentSkin(self, REQUEST=None):
'''
@@ -82,31 +117,14 @@
if REQUEST is None:
REQUEST = getattr(self, 'REQUEST', None)
if REQUEST is None:
- # We are traversing without a REQUEST at the root.
- # Don't change the skin right now. (Otherwise
- # [un]restrictedTraverse messes up the skin data.)
+ # self is not fully wrapped at the moment. Don't
+ # change anything.
return
if self._v_skindata is not None and self._v_skindata[0] is REQUEST:
# Already set up for this request.
return
- self._v_skindata = None
- sfn = self.getSkinsFolderName()
- if sfn is not None:
- # Note that our custom __getattr__ won't get confused
- # by skins at the moment because _v_skindata is None.
- sf = getattr(self, sfn, None)
- if sf is not None:
- try:
- sd = sf.getSkin(REQUEST)
- except:
- import sys
- from zLOG import LOG, ERROR
- LOG('CMFCore', ERROR, 'Unable to get skin',
- error=sys.exc_info())
- else:
- if sd is not None:
- # Hide from acquisition.
- self._v_skindata = (REQUEST, sd, {})
+ skinname = self.getSkinNameFromRequest(REQUEST)
+ self.changeSkin(skinname)
def __of__(self, parent):
'''
@@ -114,7 +132,15 @@
that Acquisition.Implicit.__of__() would return.
'''
w_self = ImplicitAcquisitionWrapper(aq_base(self), parent)
- w_self.setupCurrentSkin()
+ try:
+ w_self.setupCurrentSkin()
+ except:
+ # This shouldn't happen, even if the requested skin
+ # does not exist.
+ import sys
+ from zLOG import LOG, ERROR
+ LOG('CMFCore', ERROR, 'Unable to setupCurrentSkin()',
+ error=sys.exc_info())
return w_self
def _checkId(self, id, allow_dup=0):
=== CMF/CMFCore/SkinsContainer.py 1.5 => 1.6 ===
--- CMF/CMFCore/SkinsContainer.py:1.5 Thu Aug 1 15:05:11 2002
+++ CMF/CMFCore/SkinsContainer.py Thu Aug 22 13:45:53 2002
@@ -92,21 +92,4 @@
return None
return self.getSkinByPath(path)
- security.declarePrivate('getSkin')
- def getSkin(self, request):
- '''
- Returns the requested skin.
- '''
- varname = self.getRequestVarname()
- name = request.get(varname, None)
- skinob = None
- if name is not None:
- skinob = self.getSkinByName(name)
- if skinob is None:
- skinob = self.getSkinByName(self.getDefaultSkin())
- if skinob is None:
- skinob = self.getSkinByPath('')
- return skinob
-
-
InitializeClass( SkinsContainer )