Back to index

plone3  3.1.7
Static Public Attributes | Private Member Functions | Static Private Attributes
CMFCore.exportimport.skins.SkinsToolXMLAdapter Class Reference
Inheritance diagram for CMFCore.exportimport.skins.SkinsToolXMLAdapter:
Inheritance graph
[legend]
Collaboration diagram for CMFCore.exportimport.skins.SkinsToolXMLAdapter:
Collaboration graph
[legend]

List of all members.

Static Public Attributes

string name = 'skins'

Private Member Functions

def _exportNode
def _importNode
def _extractSkinPaths
def _purgeSkinPaths
def _initSkinPaths
def _updatePath
def _removeSkin

Static Private Attributes

string _LOGGER_ID = 'skins'

Detailed Description

XML im- and exporter for SkinsTool.

Definition at line 56 of file skins.py.


Member Function Documentation

Export the object as a DOM node.

Definition at line 67 of file skins.py.

00067 
00068     def _exportNode(self):
00069         """Export the object as a DOM node.
00070         """
00071         node = self._getObjectNode('object')
00072         node.setAttribute('default_skin', self.context.default_skin)
00073         node.setAttribute('request_varname', self.context.request_varname)
00074         node.setAttribute('allow_any', str(bool(self.context.allow_any)))
00075         node.setAttribute('cookie_persistence',
00076                           str(bool(self.context.cookie_persistence)))
00077         node.appendChild(self._extractObjects())
00078         node.appendChild(self._extractSkinPaths())
00079 
00080         self._logger.info('Skins tool exported.')
00081         return node

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 110 of file skins.py.

00110 
00111     def _extractSkinPaths(self):
00112         fragment = self._doc.createDocumentFragment()
00113         for k, v in self.context.getSkinPaths():
00114             node = self._doc.createElement('skin-path')
00115             node.setAttribute('name', k)
00116             for layer in [ l.strip() for l in v.split(',') if l.strip() ]:
00117                 child = self._doc.createElement('layer')
00118                 child.setAttribute('name', layer)
00119                 node.appendChild(child)
00120             fragment.appendChild(node)
00121         return fragment

Here is the caller graph for this function:

def CMFCore.exportimport.skins.SkinsToolXMLAdapter._importNode (   self,
  node 
) [private]
Import the object from the DOM node.

Definition at line 82 of file skins.py.

00082 
00083     def _importNode(self, node):
00084         """Import the object from the DOM node.
00085         """
00086         obj = self.context
00087 
00088         if self.environ.shouldPurge():
00089             obj.default_skin = ''
00090             obj.request_varname = 'portal_skin'
00091             obj.allow_any = 0
00092             obj.cookie_persistence = 0
00093             self._purgeObjects()
00094             self._purgeSkinPaths()
00095 
00096         if node.hasAttribute('default_skin'):
00097             obj.default_skin = str(node.getAttribute('default_skin'))
00098         if node.hasAttribute('request_varname'):
00099             obj.request_varname = str(node.getAttribute('request_varname'))
00100         if node.hasAttribute('allow_any'):
00101             allow_any = node.getAttribute('allow_any')
00102             obj.allow_any = int(self._convertToBoolean(allow_any))
00103         if node.hasAttribute('cookie_persistence'):
00104             persistence = node.getAttribute('cookie_persistence')
00105             obj.cookie_persistence = int(self._convertToBoolean(persistence))
00106         self._initObjects(node)
00107         self._initSkinPaths(node)
00108 
00109         self._logger.info('Skins tool imported.')

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 125 of file skins.py.

00125 
00126     def _initSkinPaths(self, node):
00127         for child in node.childNodes:
00128             if child.nodeName != 'skin-path':
00129                 continue
00130             path_id = str(child.getAttribute('name'))
00131             if str(child.getAttribute('remove')):
00132                 self._removeSkin(skin_name=path_id)
00133                 continue
00134             if path_id == '*':
00135                 for path_id, path in self.context._getSelections().items():
00136                     path = self._updatePath(path, child)
00137                     self.context.addSkinSelection(path_id, path)
00138             else:
00139                 path = ''
00140                 if child.hasAttribute('based-on'):
00141                     try:
00142                         basename = child.getAttribute('based-on')
00143                         path = self.context._getSelections()[basename]
00144                     except KeyError:
00145                         pass
00146                 if path_id in self.context._getSelections():
00147                     oldpath = self.context._getSelections()[path_id].split(',')
00148                     for layer in oldpath:
00149                         if layer not in path:
00150                             layernode = self._doc.createElement('layer')
00151                             layernode.setAttribute('name', layer)
00152                             if oldpath.index(layer) == 0:
00153                                 layernode.setAttribute('insert-before', '*')
00154                             else:
00155                                 pos = oldpath[oldpath.index(layer)-1]
00156                                 layernode.setAttribute('insert-after', pos)
00157                             child.appendChild(layernode)
00158                 path = self._updatePath(path, child)
00159                 self.context.addSkinSelection(path_id, path)
00160         #
00161         # Purge and rebuild the skin path, now that we have added our stuff.
00162         # Don't bother if no REQUEST is present, e.g. when running unit tests
00163         #
00164         request = getattr(self.context, 'REQUEST', None)
00165         skinnable = aq_parent(aq_inner(self.context))
00166         if request is not None and skinnable is not None:
00167             skinnable.clearCurrentSkin()
00168             skinnable.setupCurrentSkin(request)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 122 of file skins.py.

00122 
00123     def _purgeSkinPaths(self):
00124         self.context._getSelections().clear()

Here is the caller graph for this function:

def CMFCore.exportimport.skins.SkinsToolXMLAdapter._removeSkin (   self,
  skin_name = None 
) [private]
Remove a skin from the skinstool

Definition at line 209 of file skins.py.

00209 
00210     def _removeSkin(self, skin_name=None):
00211         """
00212         Remove a skin from the skinstool
00213         """
00214         skins = self.context.getSkinSelections()
00215         if skin_name in skins:
00216             self.context.manage_skinLayers(chosen=[skin_name], del_skin=1, )
00217 

Here is the caller graph for this function:

def CMFCore.exportimport.skins.SkinsToolXMLAdapter._updatePath (   self,
  path,
  node 
) [private]

Definition at line 169 of file skins.py.

00169 
00170     def _updatePath(self, path, node):
00171         path = [ name.strip() for name in path.split(',') if name.strip() ]
00172 
00173         for child in node.childNodes:
00174             if child.nodeName != 'layer':
00175                 continue
00176             layer_name = child.getAttribute('name')
00177             if layer_name in path:
00178                 path.remove(layer_name)
00179 
00180             if child.hasAttribute('insert-before'):
00181                 insert_before = child.getAttribute('insert-before')
00182                 if insert_before == '*':
00183                     path.insert(0, layer_name)
00184                     continue
00185                 else:
00186                     try:
00187                         index = path.index(insert_before)
00188                         path.insert(index, layer_name)
00189                         continue
00190                     except ValueError:
00191                         pass
00192             elif child.hasAttribute('insert-after'):
00193                 insert_after = child.getAttribute('insert-after')
00194                 if insert_after == '*':
00195                     pass
00196                 else:
00197                     try:
00198                         index = path.index(insert_after)
00199                         path.insert(index+1, layer_name)
00200                         continue
00201                     except ValueError:
00202                         pass
00203 
00204             if not child.hasAttribute('remove'):
00205                 path.append(layer_name)
00206 
00207         return str( ','.join(path) )
00208 

Here is the caller graph for this function:


Member Data Documentation

Definition at line 63 of file skins.py.

Definition at line 65 of file skins.py.


The documentation for this class was generated from the following file: