Back to index

plone3  3.1.7
SkinsContainer.py
Go to the documentation of this file.
00001 ##############################################################################
00002 #
00003 # Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
00004 #
00005 # This software is subject to the provisions of the Zope Public License,
00006 # Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
00007 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
00008 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00009 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
00010 # FOR A PARTICULAR PURPOSE.
00011 #
00012 ##############################################################################
00013 """ Base class for objects that supply skins.
00014 
00015 $Id: SkinsContainer.py 38590 2005-09-24 15:24:32Z yuppie $
00016 """
00017 
00018 from AccessControl import ClassSecurityInfo
00019 from Acquisition import aq_base
00020 from Globals import InitializeClass
00021 from zope.interface import implements
00022 
00023 from exceptions import SkinPathError
00024 from interfaces import ISkinsContainer
00025 from interfaces.portal_skins import SkinsContainer as z2ISkinsContainer
00026 from permissions import AccessContentsInformation
00027 
00028 
00029 class SkinsContainer:
00030 
00031     implements(ISkinsContainer)
00032     __implements__ = z2ISkinsContainer
00033 
00034     security = ClassSecurityInfo()
00035 
00036     security.declareProtected(AccessContentsInformation, 'getSkinPath')
00037     def getSkinPath(self, name):
00038         """ Convert a skin name to a skin path.
00039         """
00040         raise NotImplementedError
00041 
00042     security.declareProtected(AccessContentsInformation, 'getDefaultSkin')
00043     def getDefaultSkin(self):
00044         """ Get the default skin name.
00045         """
00046         raise NotImplementedError
00047 
00048     security.declareProtected(AccessContentsInformation, 'getRequestVarname')
00049     def getRequestVarname(self):
00050         """ Get the variable name to look for in the REQUEST.
00051         """
00052         raise NotImplementedError
00053 
00054     security.declarePrivate('getSkinByPath')
00055     def getSkinByPath(self, path, raise_exc=0):
00056         """ Get a skin at the given path.
00057         """
00058         baseself = aq_base(self)
00059         skinob = None
00060         parts = list( path.split(',') )
00061         parts.reverse()
00062         for part_path in parts:
00063             partob = baseself
00064             for name in part_path.strip().split('/'):
00065                 if name == '':
00066                     continue
00067                 if name[:1] == '_':
00068                     # Not allowed.
00069                     partob = None
00070                     if raise_exc:
00071                         raise SkinPathError('Underscores are not allowed')
00072                     break
00073                 # Allow acquisition tricks.
00074                 partob = getattr(partob, name, None)
00075                 if partob is None:
00076                     # Not found.  Cancel the search.
00077                     if raise_exc:
00078                         raise SkinPathError('Name not found: %s' % part_path)
00079                     break
00080             if partob is not None:
00081                 # Now partob has containment and context.
00082                 # Build the final skinob by creating an object
00083                 # that puts the former skinob in the context
00084                 # of the new skinob.
00085                 partob = aq_base(partob)
00086                 if skinob is None:
00087                     skinob = partob
00088                 else:
00089                     skinob = partob.__of__(skinob)
00090         return skinob
00091 
00092     security.declarePrivate('getSkinByName')
00093     def getSkinByName(self, name):
00094         """ Get the named skin.
00095         """
00096         path = self.getSkinPath(name)
00097         if path is None:
00098             return None
00099         return self.getSkinByPath(path)
00100 
00101 InitializeClass( SkinsContainer )