Back to index

plone3  3.1.7
Public Member Functions | Public Attributes
plone.app.contentrules.exportimport.rules.PropertyRuleElementExportImportHandler Class Reference

List of all members.

Public Member Functions

def __init__
def import_element
def export_element
def import_node
def export_field
def extract_text
def from_unicode
def field_typecast

Public Attributes

 element
 descriptor

Detailed Description

Import portlet assignment settings based on zope.schema properties

Definition at line 45 of file rules.py.


Constructor & Destructor Documentation

Definition at line 52 of file rules.py.

00052 
00053     def __init__(self, element):
00054         data = IRuleElementData(element)
00055         self.element = element
00056         self.descriptor = getUtility(IRuleElement, name=data.element)
        

Here is the caller graph for this function:


Member Function Documentation

Definition at line 66 of file rules.py.

00066 
00067     def export_element(self, doc, node):
00068         if self.descriptor.schema is None:
00069             return
00070         
00071         for field_name in self.descriptor.schema:
00072             field = self.descriptor.schema[field_name]
00073             
00074             if not IField.providedBy(field):
00075                 continue
00076             
00077             child = self.export_field(doc, field)
00078             node.appendChild(child)
00079             
        

Here is the call graph for this function:

Turn a zope.schema field into a node and return it

Definition at line 115 of file rules.py.

00115 
00116     def export_field(self, doc, field):
00117         """Turn a zope.schema field into a node and return it
00118         """
00119         
00120         field = field.bind(self.element)
00121         value = field.get(self.element)
00122         
00123         child = doc.createElement('property')
00124         child.setAttribute('name', field.__name__)
00125         
00126         if value is not None:
00127             if ICollection.providedBy(field):
00128                 for e in value:
00129                     list_element = doc.createElement('element')
00130                     list_element.appendChild(doc.createTextNode(str(e)))
00131                     child.appendChild(list_element)
00132             else:
00133                 child.appendChild(doc.createTextNode(unicode(value)))
00134             
00135         return child
        

Here is the caller graph for this function:

Definition at line 136 of file rules.py.

00136 
00137     def extract_text(self, node):
00138         node.normalize()
00139         text = u""
00140         for child in node.childNodes:
00141             if child.nodeType == node.TEXT_NODE:
00142                 text += child.nodeValue
00143         return text
        

Here is the caller graph for this function:

Definition at line 154 of file rules.py.

00154 
00155     def field_typecast(self, field, value):
00156         # A slight hack to force sequence types to the right type
00157         typecast = getattr(field, '_type', None)
00158         if typecast is not None:
00159             if not isinstance(typecast, (list, tuple)):
00160                 typecast = (typecast,)
00161             for tc in reversed(typecast):
00162                 if callable(tc):
00163                     try:
00164                         value = tc(value)
00165                         break
00166                     except:
00167                         pass
00168         return value

Here is the caller graph for this function:

Definition at line 144 of file rules.py.

00144 
00145     def from_unicode(self, field, value):
00146         
00147         # XXX: Bool incorrectly omits to declare that it implements
00148         # IFromUnicode, even though it does.
00149         import zope.schema
00150         if IFromUnicode.providedBy(field) or isinstance(field, zope.schema.Bool):
00151             return field.fromUnicode(value)
00152         else:
00153             return self.field_typecast(field, value)
    

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 57 of file rules.py.

00057 
00058     def import_element(self, node):
00059         
00060         if self.descriptor.schema is None:
00061             return
00062             
00063         for child in node.childNodes:
00064             if child.nodeName == 'property':
00065                 self.import_node(self.descriptor.schema, child)
    

Here is the call graph for this function:

Import a single <property /> node

Definition at line 82 of file rules.py.

00082 
00083     def import_node(self, interface, child):
00084         """Import a single <property /> node
00085         """
00086         property_name = child.getAttribute('name')
00087         
00088         field = interface.get(property_name, None)
00089         if field is None:
00090             return
00091         
00092         field = field.bind(self.element)
00093         value = None
00094         
00095         # If we have a collection, we need to look at the value_type.
00096         # We look for <element>value</element> child nodes and get the
00097         # value from there
00098         if ICollection.providedBy(field):
00099             value_type = field.value_type
00100             value = []
00101             for element in child.childNodes:
00102                 if element.nodeName != 'element':
00103                     continue
00104                 element_value = self.extract_text(element)
00105                 value.append(self.from_unicode(value_type, element_value))
00106             value = self.field_typecast(field, value)
00107         
00108         # Otherwise, just get the value of the <property /> node
00109         else:
00110             value = self.extract_text(child)
00111             value = self.from_unicode(field, value)
00112             
00113         field.validate(value)
00114         field.set(self.element, value)
        

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 55 of file rules.py.

Definition at line 54 of file rules.py.


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