[CMF-checkins] CVS: CMF/CMFCore - Skinnable.py:1.6.2.1 SkinsContainer.py:1.5.2.1
runyaga
runyaga@thisbox.com
Fri, 9 Aug 2002 14:04:08 -0400
Update of /cvs-repository/CMF/CMFCore
In directory cvs.zope.org:/tmp/cvs-serv30565
Modified Files:
Tag: SkinApplyToSkinnable-branch
Skinnable.py SkinsContainer.py
Log Message:
applying the skin to the REQUEST was done in the SkinsContainer.
moved this out to the Skinnable.py class (PortalObject). where it
now has a seperate method called changeSkin(name). The skinnable object
will now do the apply of the skins to the PortalObject._v_skindata
We do this so we can change the skin during a REQUEST. the setupCurrentSkin
stopped work when shane introduced some optimization. I'm not quite sure
how 'unoptimized' this change is. but it works. I posted to plone-dev mailing list
on how to apply a skin conditionally.
main concept: we want to be able to see the environment and 'toggle' the skin
through a Script(Python) bound by a Access Rule
=== CMF/CMFCore/Skinnable.py 1.6 => 1.6.2.1 ===
--- CMF/CMFCore/Skinnable.py:1.6 Thu Aug 1 15:05:11 2002
+++ CMF/CMFCore/Skinnable.py Fri Aug 9 14:04:07 2002
@@ -23,7 +23,7 @@
from Acquisition import ImplicitAcquisitionWrapper, aq_base, aq_inner
from ExtensionClass import Base
from AccessControl import ClassSecurityInfo
-
+from utils import getToolByName
# superGetAttr is assigned to whatever ObjectManager.__getattr__
# used to do.
@@ -37,7 +37,6 @@
_marker = [] # Create a new marker object.
-
class SkinnableObjectManager (ObjectManager):
_v_skindata = None
@@ -71,7 +70,48 @@
if superGetAttr is None:
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, {})
+ else:
+ import sys
+ from zLOG import LOG, ERROR
+ LOG('CMFCore', ERROR, 'Unable to change skin',
+ error=sys.exc_info())
+
security.declarePublic('setupCurrentSkin')
def setupCurrentSkin(self, REQUEST=None):
'''
@@ -89,25 +129,9 @@
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):
'''
Sneakily sets up the portal skin then returns the wrapper
=== CMF/CMFCore/SkinsContainer.py 1.5 => 1.5.2.1 ===
--- CMF/CMFCore/SkinsContainer.py:1.5 Thu Aug 1 15:05:11 2002
+++ CMF/CMFCore/SkinsContainer.py Fri Aug 9 14:04:07 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 )