Author: jmorliaguet
Date: Mon May  1 14:45:32 2006
New Revision: 3005

Modified:
   cpsskins/branches/paris-sprint-2006/setup/README.txt
   cpsskins/branches/paris-sprint-2006/setup/interfaces.py
   cpsskins/branches/paris-sprint-2006/setup/io.py
   cpsskins/branches/paris-sprint-2006/ui/screens/sitemanager/views.py
Log:

- made it possible to ignore fields during the XML export



Modified: cpsskins/branches/paris-sprint-2006/setup/README.txt
==============================================================================
--- cpsskins/branches/paris-sprint-2006/setup/README.txt        (original)
+++ cpsskins/branches/paris-sprint-2006/setup/README.txt        Mon May  1 
14:45:32 2006
@@ -496,12 +496,13 @@
 
     >>> from cpsskins.setup.interfaces import IDOMAdapter
 
-    >>> def toXML(obj, title=u'resources', attributes=()):
+    >>> def toXML(obj, title=u'resources', attributes=(), ignored=()):
     ...     document = dom.createDocument(None, title, None)
     ...     doc = document.documentElement
     ...     exporter = getMultiAdapter((obj, doc), IDOMAdapter)
     ...     exporter.setDocument(document)
     ...     exporter.writeAsAttributes(attributes)
+    ...     exporter.ignoreFields(ignored)
     ...     exporter.save()
     ...     return document.toprettyxml(indent=u'  ', encoding=u'utf-8')
 
@@ -591,18 +592,20 @@
     >>> slot = Slot(u'Some slot', slot=u'slot1')
     >>> pageblock[u'cell1'][u'slot'] = slot
 
-    >>> print toXML(pageblock, u'elements', (u'title', u'description'))
+    >>> print toXML(pageblock, u'elements', (u'title', u'description'),
+    ...             (u'slot',))
     <?xml version="1.0" encoding="utf-8"?>
     <elements>
       <pageblock id="12345" title="Some page block">
         <cell id="12345" title="Some cell 1">
-          <slot description="" id="12345" title="Some slot" slot="slot1"/>
+          <slot description="" id="slot1" title="Some slot"/>
         </cell>
         <cell id="12345" title="Some cell 2"/>
       </pageblock>
     </elements>
     <BLANKLINE>
 
+
 Export of container elements
 ----------------------------
 
@@ -610,7 +613,7 @@
     >>> root = getRootFolder()
     >>> theme = addThemeSkeleton(tmutil)
 
-    >>> print toXML(theme, u'themes', (u'title', ))
+    >>> print toXML(theme, u'themes', (u'title', ), (u'slot',))
     <?xml version="1.0" encoding="utf-8"?>
     <themes>
       <theme id="12345" title="A theme">
@@ -631,7 +634,7 @@
     >>> print toXML(portlet, u'portlets',  (u'title', ))
     <?xml version="1.0" encoding="utf-8"?>
     <portlets>
-      <portlet id="12345" title="Action portlet">
+      <portlet id="12345" title="Action portlet" type="standard.actions">
         <category value="zmi_views"/>
       </portlet>
     </portlets>

Modified: cpsskins/branches/paris-sprint-2006/setup/interfaces.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/setup/interfaces.py     (original)
+++ cpsskins/branches/paris-sprint-2006/setup/interfaces.py     Mon May  1 
14:45:32 2006
@@ -141,7 +141,10 @@
 
     mapping = Attribute(u"Mapping between old and new URIs")
 
-    attributes = Attribute(u"The list of fields written as DOM attributes.")
+    ignored_fields = Attribute(u"The list of ignored fields.")
+
+    fields_as_attributes = Attribute(
+                           u"The list of fields written as DOM attributes.")
 
     def setDocument(document):
         """Set the document element"""
@@ -149,9 +152,12 @@
     def getDocument():
         """Get the document element"""
 
-    def writeAsAttributes(attributes):
+    def writeAsAttributes(fields):
         """Set the list of fields written as attributes."""
 
+    def ignoreFields(fields):
+        """Set the list of ignored fields."""
+
     def setURIMapping(mapping):
         """Set the URI mapping."""
 

Modified: cpsskins/branches/paris-sprint-2006/setup/io.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/setup/io.py     (original)
+++ cpsskins/branches/paris-sprint-2006/setup/io.py     Mon May  1 14:45:32 2006
@@ -36,7 +36,8 @@
     """
     document = None
     mapping = {}
-    attributes = ()
+    ignored_fields = ()
+    fields_as_attributes = ()
 
     def __init__(self, context, node):
         self.context = context
@@ -51,8 +52,11 @@
                 "use setDocument(document) to set the document element.")
         return self.document
 
-    def writeAsAttributes(self, attributes):
-        self.attributes = attributes
+    def writeAsAttributes(self, fields):
+        self.fields_as_attributes = fields
+
+    def ignoreFields(self, fields):
+        self.ignored_fields = fields
 
     def setURIMapping(self, mapping):
         self.mapping = mapping
@@ -67,6 +71,14 @@
         """
         raise NotImplementedError
 
+    def clone(self, other):
+        """Clone the DOM adapter.
+        """
+        self.setDocument(other.document)
+        self.writeAsAttributes(other.fields_as_attributes)
+        self.ignoreFields(other.ignored_fields)
+        self.setURIMapping(other.mapping)
+
 class DOMAdapter(BaseDOMAdapter):
     """Generic DOM adapter
     """
@@ -74,11 +86,11 @@
 
     _reserved_attrs = u'id', u'type'
 
-    def writeAsAttributes(self, attributes):
+    def writeAsAttributes(self, fields):
         for attr in self._reserved_attrs:
-            if attr in attributes:
+            if attr in fields:
                 raise ValueError("'%s' is a reserved attribute." % attr)
-        self.attributes = attributes
+        self.fields_as_attributes = fields
 
     def save(self):
         context = self.context
@@ -98,6 +110,9 @@
         schema = type.getContentType()
 
         for attr, field in zope.schema.getFieldsInOrder(schema):
+            if attr in self.ignored_fields:
+                continue
+
             obj = getattr(context, attr)
 
             field_io = IFieldIO(field, None)
@@ -107,7 +122,7 @@
                 value = field_io.dump(obj)
 
             # set the property as an attribute,
-            if attr in self.attributes:
+            if attr in self.fields_as_attributes:
                 element_el.setAttribute(attr, value)
 
             # or as a child element
@@ -124,8 +139,7 @@
             for child in context:
                 exporter = getMultiAdapter((context[child], element_el),
                                             IDOMAdapter)
-                exporter.setDocument(document)
-                exporter.writeAsAttributes(self.attributes)
+                exporter.clone(self)
                 exporter.save()
 
     def load(self):

Modified: cpsskins/branches/paris-sprint-2006/ui/screens/sitemanager/views.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/ui/screens/sitemanager/views.py 
(original)
+++ cpsskins/branches/paris-sprint-2006/ui/screens/sitemanager/views.py Mon May 
 1 14:45:32 2006
@@ -303,6 +303,7 @@
             exporter = getMultiAdapter((theme, root), IDOMAdapter)
             exporter.setDocument(document)
             exporter.writeAsAttributes((u'title', u'description'))
+            exporter.ignoreFields((u'slot',))
             exporter.save()
 
         xml = document.toprettyxml(indent=u'  ', encoding=u'utf-8')
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to