Author: jmorliaguet
Date: Fri Apr  7 22:21:45 2006
New Revision: 2786

Removed:
   cpsskins/branches/jmo-perspectives/standard/io/element.xml
Modified:
   cpsskins/branches/jmo-perspectives/setup/README.txt
   cpsskins/branches/jmo-perspectives/standard/io/element.py
Log:

- fixed the xml export of elements / subelements



Modified: cpsskins/branches/jmo-perspectives/setup/README.txt
==============================================================================
--- cpsskins/branches/jmo-perspectives/setup/README.txt (original)
+++ cpsskins/branches/jmo-perspectives/setup/README.txt Fri Apr  7 22:21:45 2006
@@ -487,15 +487,43 @@
     >>> root['pageblock'] = pageblock
 
     >>> from cpsskins.elements.cell import Cell
-    >>> cell = Cell(u'Some cell')
+    >>> cell1 = Cell(u'Some cell 1')
+    >>> cell2 = Cell(u'Some cell 2')
 
-    >>> pageblock[u'cell'] = cell
+    >>> pageblock[u'cell1'] = cell1
+    >>> pageblock[u'cell2'] = cell2
+
+    >>> from cpsskins.elements.slot import Slot
+    >>> slot = Slot(u'Some slot')
+    >>> pageblock[u'cell1'][u'slot'] = slot
 
     >>> exporter = getMultiAdapter((pageblock, request), IDataExporter)
     >>> print exporter()
     <?xml version="1.0"?>
-    <element uri="canvas-pageblock-12345"
-             title="Some page block"/>
+    <element
+      uri="canvas-pageblock-12345"
+      title="Some page block"
+      parent=""/>
+    <element
+      uri="canvas-cell-12345"
+      title="Some cell 1"
+      parent="canvas-pageblock-12345"/>
+    <element
+      uri="canvas-slot-"
+      title="Some slot"
+      parent="canvas-cell-12345"/>
+    <element
+      uri="canvas-cell-12345"
+      title="Some cell 2"
+      parent="canvas-pageblock-12345"/>
+    <element
+      uri="canvas-cell-12345"
+      title="Some cell 1"
+      parent="canvas-pageblock-12345"/>
+    <element
+      uri="canvas-slot-"
+      title="Some slot"
+      parent="canvas-cell-12345"/>
     <BLANKLINE>
 
 

Modified: cpsskins/branches/jmo-perspectives/standard/io/element.py
==============================================================================
--- cpsskins/branches/jmo-perspectives/standard/io/element.py   (original)
+++ cpsskins/branches/jmo-perspectives/standard/io/element.py   Fri Apr  7 
22:21:45 2006
@@ -19,40 +19,39 @@
 
 from xml.dom.minidom import parseString
 
-from zope.app import pagetemplate
 from zope.component import adapts
 from zope.interface import implements
 
 from cpsskins.elements.interfaces import IElement, IIdentifiable
 from cpsskins.setup.interfaces import IDataExporter, IDataImporter
 
+XML = u"""<element
+  uri="%(uri)s"
+  title="%(title)s"
+  parent="%(parent)s"/>
+"""
+
 class Exporter(object):
     """Export an element.
     """
     implements(IDataExporter)
 
-    template = pagetemplate.ViewPageTemplateFile('element.xml')
-
     def __init__(self, context, request):
         self.context = context
         self.request = request
 
     def __call__(self):
-        return self.to_xml(self.context)
+        return u'<?xml version="1.0"?>\n' + self.toXML(self.context)
 
-    def to_xml(self, node, xml=u''):
-        for child in list(node):
-            xml += self.to_xml(node[child], xml=xml)
-        return self.template(info=self.getInfo(node))
+    def toXML(self, node=None, parent=None, xml=u''):
+        for child in node:
+            xml += self.toXML(node[child], parent=node, xml=xml)
 
-    def getInfo(self, node):
-        return {
+        return XML % {
             'title': node.title,
             'uri': IIdentifiable(node).getURI(),
-        }
-
-    def getChildNodes(self):
-        return list(self.context)
+            'parent': parent and IIdentifiable(parent).getURI() or u'',
+        } + xml
 
 class Importer(object):
     """Import an element.
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to