Back to index

plone3  3.1.7
Private Member Functions | Static Private Attributes
GenericSetup.utils.PropertyManagerHelpers Class Reference

List of all members.

Private Member Functions

def _extractProperties
def _purgeProperties
def _initProperties

Static Private Attributes

 _encoding = default_encoding

Detailed Description

PropertyManager im- and export helpers.

Definition at line 637 of file utils.py.


Member Function Documentation

Definition at line 644 of file utils.py.

00644 
00645     def _extractProperties(self):
00646         fragment = self._doc.createDocumentFragment()
00647 
00648         for prop_map in self.context._propertyMap():
00649             prop_id = prop_map['id']
00650             if prop_id == 'i18n_domain':
00651                 continue
00652 
00653             # Don't export read-only nodes
00654             if 'w' not in prop_map.get('mode', 'wd'):
00655                 continue
00656 
00657             node = self._doc.createElement('property')
00658             node.setAttribute('name', prop_id)
00659 
00660             prop = self.context.getProperty(prop_id)
00661             if isinstance(prop, (tuple, list)):
00662                 for value in prop:
00663                     if isinstance(value, str):
00664                         value.decode(self._encoding)
00665                     child = self._doc.createElement('element')
00666                     child.setAttribute('value', value)
00667                     node.appendChild(child)
00668             else:
00669                 if prop_map.get('type') == 'boolean':
00670                     prop = unicode(bool(prop))
00671                 elif isinstance(prop, str):
00672                     prop = prop.decode(self._encoding)
00673                 elif not isinstance(prop, basestring):
00674                     prop = unicode(prop)
00675                 child = self._doc.createTextNode(prop)
00676                 node.appendChild(child)
00677 
00678             if 'd' in prop_map.get('mode', 'wd') and not prop_id == 'title':
00679                 prop_type = prop_map.get('type', 'string')
00680                 node.setAttribute('type', unicode(prop_type))
00681                 select_variable = prop_map.get('select_variable', None)
00682                 if select_variable is not None:
00683                     node.setAttribute('select_variable', select_variable)
00684 
00685             if hasattr(self, '_i18n_props') and prop_id in self._i18n_props:
00686                 node.setAttribute('i18n:translate', '')
00687 
00688             fragment.appendChild(node)
00689 
00690         return fragment

Here is the caller graph for this function:

def GenericSetup.utils.PropertyManagerHelpers._initProperties (   self,
  node 
) [private]

Definition at line 709 of file utils.py.

00709 
00710     def _initProperties(self, node):
00711         obj = self.context
00712         if node.hasAttribute('i18n:domain'):
00713             i18n_domain = str(node.getAttribute('i18n:domain'))
00714             obj._updateProperty('i18n_domain', i18n_domain)
00715         for child in node.childNodes:
00716             if child.nodeName != 'property':
00717                 continue
00718             prop_id = str(child.getAttribute('name'))
00719             prop_map = obj.propdict().get(prop_id, None)
00720 
00721             if prop_map is None:
00722                 if child.hasAttribute('type'):
00723                     val = str(child.getAttribute('select_variable'))
00724                     prop_type = str(child.getAttribute('type'))
00725                     obj._setProperty(prop_id, val, prop_type)
00726                     prop_map = obj.propdict().get(prop_id, None)
00727                 else:
00728                     raise ValueError("undefined property '%s'" % prop_id)
00729 
00730             if not 'w' in prop_map.get('mode', 'wd'):
00731                 raise BadRequest('%s cannot be changed' % prop_id)
00732 
00733             elements = []
00734             for sub in child.childNodes:
00735                 if sub.nodeName == 'element':
00736                     value = sub.getAttribute('value')
00737                     elements.append(value.encode(self._encoding))
00738 
00739             if elements or prop_map.get('type') == 'multiple selection':
00740                 prop_value = tuple(elements) or ()
00741             elif prop_map.get('type') == 'boolean':
00742                 prop_value = self._convertToBoolean(self._getNodeText(child))
00743             else:
00744                 # if we pass a *string* to _updateProperty, all other values
00745                 # are converted to the right type
00746                 prop_value = self._getNodeText(child).encode(self._encoding)
00747 
00748             if not self._convertToBoolean(child.getAttribute('purge')
00749                                           or 'True'):
00750                 # If the purge attribute is False, merge sequences
00751                 prop = obj.getProperty(prop_id)
00752                 if isinstance(prop, (tuple, list)):
00753                     prop_value = (tuple([p for p in prop
00754                                          if p not in prop_value]) +
00755                                   tuple(prop_value))
00756 
00757             obj._updateProperty(prop_id, prop_value)
00758 

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 691 of file utils.py.

00691 
00692     def _purgeProperties(self):
00693         for prop_map in self.context._propertyMap():
00694             mode = prop_map.get('mode', 'wd')
00695             if 'w' not in mode:
00696                 continue
00697             prop_id = prop_map['id']
00698             if 'd' in mode and not prop_id == 'title':
00699                 self.context._delProperty(prop_id)
00700             else:
00701                 prop_type = prop_map.get('type')
00702                 if prop_type == 'multiple selection':
00703                     prop_value = ()
00704                 elif prop_type in ('int', 'float'):
00705                     prop_value = 0
00706                 else:
00707                     prop_value = ''
00708                 self.context._updateProperty(prop_id, prop_value)

Here is the caller graph for this function:


Member Data Documentation

GenericSetup.utils.PropertyManagerHelpers._encoding = default_encoding [static, private]

Definition at line 642 of file utils.py.


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