Changeset 1431 in products


Ignore:
Timestamp:
Dec 6, 2009 1:59:56 PM (17 years ago)
Author:
piv
Message:

fix encoding problems in propertymanager section, lines properties are now extracted into text nodes instead of element attributes, xml.dom.minidom does not allow non-ascii characters in element attributes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • quintagroup.transmogrifier/branches/plone-2.1/quintagroup.transmogrifier/quintagroup/transmogrifier/propertymanager.py

    r461 r1431  
    22 
    33from zope.interface import classProvides, implements 
    4  
    5 from ZPublisher.HTTPRequest import default_encoding 
    64 
    75from collective.transmogrifier.interfaces import ISection, ISectionBlueprint 
     
    2018    """ 
    2119 
    22     _encoding = default_encoding 
     20    _encoding = 'utf-8' 
    2321 
    2422    def _getNodeText(self, node): 
     
    5250                for value in prop: 
    5351                    if isinstance(value, str): 
    54                         value.decode(self._encoding) 
     52                        value = value.decode(self._encoding) 
    5553                    child = self._doc.createElement('element') 
    56                     child.setAttribute('value', value) 
     54                    child.appendChild(self._doc.createTextNode(value)) 
    5755                    node.appendChild(child) 
    5856            else: 
     
    124122            for sub in child.childNodes: 
    125123                if sub.nodeName == 'element': 
    126                     value = sub.getAttribute('value') 
    127                     elements.append(value.encode(self._encoding)) 
     124                    if len(sub.childNodes) > 0: 
     125                        value = sub.childNodes[0].nodeValue 
     126                        if isinstance(value, unicode): 
     127                            value = value.encode(self._encoding) 
     128                        elements.append(value) 
    128129 
    129130            if elements or prop_map.get('type') == 'multiple selection': 
     
    197198                if node.hasChildNodes(): 
    198199                    doc.appendChild(node) 
    199                     data = doc.toprettyxml(indent='  ', encoding='utf-8') 
     200                    try: 
     201                        data = doc.toprettyxml(indent='  ', encoding='utf-8') 
     202                    except Exception, e: 
     203                        import pdb;pdb.set_trace() 
    200204                    doc.unlink() 
    201205 
Note: See TracChangeset for help on using the changeset viewer.