Author: jmorliaguet
Date: Mon May  1 21:55:33 2006
New Revision: 3011

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/standard/io/relation.py
   cpsskins/branches/paris-sprint-2006/thememanager.py
   cpsskins/branches/paris-sprint-2006/ui/screens/sitemanager/views.py
Log:

- saving work



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 
21:55:33 2006
@@ -547,7 +547,9 @@
     >>> print toXML(relation, u'relations')
     <?xml version="1.0" encoding="utf-8"?>
     <relations>
-      <monad first="cpsskins://canvas-portlet-standard.actions:12345" 
predicate="_ A"/>
+      <monad predicate="_ A">
+        <relate uri="cpsskins://canvas-portlet-standard.actions:12345"/>
+      </monad>
     </relations>
     <BLANKLINE>
 
@@ -564,7 +566,10 @@
     >>> print toXML(relation, u'relations')
     <?xml version="1.0" encoding="utf-8"?>
     <relations>
-      <dyad first="cpsskins://canvas-portlet-standard.actions:12345" 
predicate="_ B _" 
second="cpsskins://canvas-portlet-standard.breadcrumbs:12345"/>
+      <dyad predicate="_ B _">
+        <relate uri="cpsskins://canvas-portlet-standard.actions:12345"/>
+        <relate uri="cpsskins://canvas-portlet-standard.breadcrumbs:12345"/>
+      </dyad>
     </relations>
     <BLANKLINE>
 
@@ -582,12 +587,15 @@
     >>> print toXML(relation, u'relations')
     <?xml version="1.0" encoding="utf-8"?>
     <relations>
-      <triad first="cpsskins://canvas-portlet-standard.actions:12345" 
predicate="_ C _ D _" 
second="cpsskins://canvas-portlet-standard.breadcrumbs:12345" 
third="cpsskins://canvas-slot:slotA"/>
+      <triad predicate="_ C _ D _">
+        <relate uri="cpsskins://canvas-portlet-standard.actions:12345"/>
+        <relate uri="cpsskins://canvas-portlet-standard.breadcrumbs:12345"/>
+        <relate uri="cpsskins://canvas-slot:slotA"/>
+      </triad>
     </relations>
     <BLANKLINE>
 
 
-
 Export of elements
 ------------------
 

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 
21:55:33 2006
@@ -139,6 +139,8 @@
 
     document = Attribute(u"The document element.")
 
+    objecttype = Attribute(u"Type name of objects.")
+
     mapping = Attribute(u"Mapping between old and new URIs")
 
     ignored_fields = Attribute(u"The list of ignored fields.")
@@ -152,6 +154,9 @@
     def getDocument():
         """Get the document element"""
 
+    def setObjectType(type):
+        """Set the type of objects."""
+
     def writeAsAttributes(fields):
         """Set the list of fields written as attributes."""
 

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 21:55:33 2006
@@ -18,16 +18,20 @@
 __docformat__ = "reStructuredText"
 
 import logging
+from xml.dom.minidom import Node
 
 import zope.schema
 
 from zope.component import adapts, getMultiAdapter, getUtilitiesFor
+from zope.component import createObject
+from zope.component.interfaces import ComponentLookupError
 from zope.interface import implements, Interface
 from zope.app.container.interfaces import IItemContainer
 
 from cpsskins.relations.interfaces import IRelatable
 from cpsskins.setup.interfaces import IDOMAdapter, IIdentifiable, IType
 from cpsskins.setup.interfaces import IDOMAdapter, IIdentifiable
+from cpsskins.storage.storage import IStorage
 
 logger = logging.getLogger("cpsskins")
 
@@ -35,8 +39,13 @@
     """Base class for DOM adapters.
     """
     document = None
+
+    objecttype = u''
+
     mapping = {}
+
     ignored_fields = ()
+
     fields_as_attributes = ()
 
     def __init__(self, context, node):
@@ -52,6 +61,9 @@
                 "use setDocument(document) to set the document element.")
         return self.document
 
+    def setObjectType(self, type):
+        self.objecttype = type
+
     def writeAsAttributes(self, fields):
         self.fields_as_attributes = fields
 
@@ -78,6 +90,7 @@
         self.writeAsAttributes(other.fields_as_attributes)
         self.ignoreFields(other.ignored_fields)
         self.setURIMapping(other.mapping)
+        self.setObjectType(other.objecttype)
 
 class DOMAdapter(BaseDOMAdapter):
     """Generic DOM adapter
@@ -148,20 +161,48 @@
 
         schema = IType(context).getContentType()
 
-        _marker = object()
-
+        # properties
         for name, field in zope.schema.getFieldsInOrder(schema):
+            if name in self.ignored_fields:
+                continue
+
             text = node.getAttribute(name)
 
             field_io = IFieldIO(field, None)
             if field_io is None:
                 raise TypeError("No field adapter found for '%s'." % field)
+            try:
+                value = field_io.load(text)
+                setattr(context, name, value)
+            except: # for testing - should not occur
+                print text
+
+        # child nodes
+        for child_el in node.childNodes:
+            if child_el.nodeType != Node.ELEMENT_NODE:
+                continue
+
+            contentname = child_el.getAttribute(u'type') or child_el.tagName
+            factory_name = u'cpsskins.%s.%s' % (self.objecttype, contentname)
+
+            try:
+                element = createObject(factory_name)
+            except ComponentLookupError: # FIXME:
+                continue
+
+            importer = getMultiAdapter((element, node), IDOMAdapter)
+            importer.clone(self)
+            importer.load()
+
+            if IStorage.providedBy(context):
+                context.add(element)
             else:
-                try:
-                    value = field_io.load(text)
-                    setattr(context, name, value)
-                except:
-                    print text
+                context[contentname] = element
+
+            typename = IType(element).getTypeName()
+            old_uri = '%s:%s' % (typename, child_el.getAttribute(u'id'))
+            new_uri = IIdentifiable(element).getURI()
+            importer.setURIMapping({old_uri: new_uri})
 
 
 #######################################################################

Modified: cpsskins/branches/paris-sprint-2006/standard/io/relation.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/standard/io/relation.py (original)
+++ cpsskins/branches/paris-sprint-2006/standard/io/relation.py Mon May  1 
21:55:33 2006
@@ -22,12 +22,6 @@
 from cpsskins.setup.interfaces import IDOMAdapter, IIdentifiable, IType
 from cpsskins.setup.io import BaseDOMAdapter
 
-relates = {
-    1: u'first',
-    2: u'second',
-    3: u'third',
-}
-
 class DOMAdapter(BaseDOMAdapter):
     """DOM adapter for relations
     """
@@ -42,10 +36,10 @@
         relation_el = document.createElement(IType(context).contentname)
         relation_el.setAttribute(u'predicate', str(context))
 
-        i = 1
         for relate in context:
-            relation_el.setAttribute(relates[i], 
IIdentifiable(relate).getURI())
-            i += 1
+            relate_el = document.createElement(u'relate')
+            relate_el.setAttribute(u'uri', IIdentifiable(relate).getURI())
+            relation_el.appendChild(relate_el)
 
         node.appendChild(relation_el)
 
@@ -53,6 +47,18 @@
         context = self.context
         node = self.node
 
-        print context
-        # TODO
+        context.predicate = node.getAttribute(u'predicate')
+        relates = ()
+
+        for relate_el in node.getElementsByTagName('relate'):
+            uri = relate_el.getAttribute(u'uri')
+            #uri = self.mapping[uri]
+
+            #print '%s -> %s' % (uri, self.mapping.get(uri))
+
+            obj = uri # FIXME: resolve the uri
+
+            relates += obj,
+
+        context.relates = relates
 

Modified: cpsskins/branches/paris-sprint-2006/thememanager.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/thememanager.py (original)
+++ cpsskins/branches/paris-sprint-2006/thememanager.py Mon May  1 21:55:33 2006
@@ -108,6 +108,12 @@
     def getThemes():
         """Return the list of available themes."""
 
+    def deleteTheme(name):
+        """Delete a theme."""
+
+    def deleteAllThemes():
+        """Delete all themes."""
+
     def getThemeByName(name):
         """Return a theme by its name."""
 
@@ -140,15 +146,6 @@
     """A theme management utility that can contain multiple .
     themes
 
-    >>> from zope.interface.verify import verifyClass
-    >>> verifyClass(IThemeManagementFolder, ThemeManagementFolder)
-    True
-
-    >>> from cpsskins.thememanager import ThemeManagementFolder
-    >>> from cpsskins.thememanager import IThemeManagementFolder
-    >>> gsm = zapi.getGlobalSiteManager()
-    >>> gsm.registerUtility(ThemeManagementFolder(), IThemeManagementFolder,
-    ...                     name=u'themes')
     """
 
     implements(IThemeManagementFolder, IThemeContainer)
@@ -257,6 +254,23 @@
         """
         return [theme for name, theme in self.getUtilitiesFor(ITheme)]
 
+    def deleteTheme(self, name=u''):
+        """Delete a theme
+        """
+        for k, v in self.getUtilitiesFor(ITheme):
+            if k == name:
+                self.unregisterUtility(v, ITheme, k)
+                del self[zapi.getName(v)]
+                print 'deleted' + k
+                return
+
+        raise KeyError("No such theme: %s." % name)
+
+    def deleteAllThemes(self):
+        for k, v in self.getUtilitiesFor(ITheme):
+            self.unregisterUtility(v, ITheme, k)
+            del self[zapi.getName(v)]
+
     def getThemeByName(self, name=u''):
         """Return a theme by its name.
         """

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 21:55:33 2006
@@ -19,6 +19,7 @@
 
 from xml.dom.minidom import parseString, DOMImplementation, Node
 
+from zope.app import zapi
 from zope.app.interface import queryType
 from zope.app.file import File
 from zope.component import getUtilitiesFor, getUtility, getMultiAdapter
@@ -170,8 +171,7 @@
         uri_mapping = {}
 
         # themes
-        themes_data = archive[u'themes.xml']
-        self.importThemes(themes_data)
+        uri_mapping.update(self.importThemes(archive[u'themes.xml']))
 
         # storages
         for storage_id in u'formats', u'displays', u'portlets':
@@ -281,18 +281,18 @@
         uri_mapping = {}
 
         storage_configuration = getUtility(configuration.IStorage, name)
-        itemtype = storage_configuration.itemtype
+        typename = getTypeName(storage_configuration.itemtype)
 
         for el in root.childNodes:
             if el.nodeType != Node.ELEMENT_NODE:
                 continue
             contentname = el.getAttribute('type') or el.tagName
-            resourcename = getTypeName(itemtype)
-            factory_name = u'cpsskins.%s.%s' % (resourcename, contentname)
+            factory_name = u'cpsskins.%s.%s' % (typename, contentname)
             obj = createObject(factory_name)
 
             importer = getMultiAdapter((obj, el), IDOMAdapter)
             importer.setDocument(document)
+            importer.setObjectType(typename)
             importer.load()
 
             storage.add(obj)
@@ -330,7 +330,21 @@
 
         uri_mapping = {}
 
-        # TODO
+        mgr = getThemeManager(self.context)
+        mgr.deleteAllThemes()
+
+        document = parseString(xml)
+        root = document.documentElement
+
+        for el in root.childNodes:
+            if el.nodeType != Node.ELEMENT_NODE:
+                continue
+
+            #importer = getMultiAdapter((obj, el), IDOMAdapter)
+            #importer.setDocument(document)
+            #importer.setObjectType(typename)
+            #importer.load()
 
         document.unlink()
         return uri_mapping
+
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to