[Erp5-report] r45296 luke - /erp5/trunk/products/ERP5/Document/BusinessTemplate.py

nobody at svn.erp5.org nobody at svn.erp5.org
Mon Apr 11 17:47:53 CEST 2011


Author: luke
Date: Mon Apr 11 17:47:53 2011
New Revision: 45296

URL: http://svn.erp5.org?rev=45296&view=rev
Log:
 - fix removal of virutal paths done in http://svn.erp5.org/?view=revision&revision=33779

As it is possible to have non unique paths from Business Template point of view
(like having same file name for Test and Document) it is required to have "magically"
generated unique paths.

As Business Template internal data migration is unwanted, BusinessTemplate._objects
are not modified. So, while installing new Business Template, no magic is applied, but
becuase of different way of doing fresh installation and upgrade during fresh
installation problems of conflicting paths does not appear.

Modified:
    erp5/trunk/products/ERP5/Document/BusinessTemplate.py

Modified: erp5/trunk/products/ERP5/Document/BusinessTemplate.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Document/BusinessTemplate.py?rev=45296&r1=45295&r2=45296&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Document/BusinessTemplate.py [utf8] (original)
+++ erp5/trunk/products/ERP5/Document/BusinessTemplate.py [utf8] Mon Apr 11 17:47:53 2011
@@ -3337,6 +3337,16 @@ class DocumentTemplateItem(BaseTemplateI
   local_file_importer_name = staticmethod(importLocalDocument)
   local_file_remover_name = staticmethod(removeLocalDocument)
 
+  def _getKey(self, path):
+    """Magical method to generate dynamic unique path"""
+    return '/'.join((self.getTemplateTypeName(), path))
+
+  def _getPath(self, key):
+    """Magical method to extract real path"""
+    if '/' in key:
+      return key.split('/')[1]
+    return key
+
   def build(self, context, **kw):
     BaseTemplateItem.build(self, context, **kw)
     for key in self._archive.iterkeys():
@@ -3359,17 +3369,20 @@ class DocumentTemplateItem(BaseTemplateI
           new_obj_code = self._objects[path]
           old_obj_code = installed_item._objects[path]
           if new_obj_code != old_obj_code:
+            # Note: Magical way to have unique paths
             modified_object_list.update(
-                {path : ['Modified', self.__class__.__name__[:-12]]})
+                {self._getKey(path) : ['Modified', self.__class__.__name__[:-12]]})
         else: # new object
+          # Note: Magical way to have unique paths
           modified_object_list.update(
-                {path : ['New', self.__class__.__name__[:-12]]})
+                {self._getKey(path) : ['New', self.__class__.__name__[:-12]]})
           # get removed object
       old_keys = installed_item._objects.keys()
       for path in old_keys:
         if path not in new_keys:
+          # Note: Magical way to have unique paths
           modified_object_list.update(
-                {path : ['Removed', self.__class__.__name__[:-12]]})
+                {self._getKey(path) : ['Removed', self.__class__.__name__[:-12]]})
     return modified_object_list
 
   def _resetDynamicModules(self):
@@ -3423,6 +3436,16 @@ class DocumentTemplateItem(BaseTemplateI
         if self.local_file_importer_name is not None:
           self.local_file_importer_name(id)
 
+  def remove(self, context, **kw):
+    """Conversion of magically uniqued paths to real ones"""
+    remove_object_dict = kw.get('remove_object_dict', {})
+    new_remove_dict = dict()
+    for k,v in remove_object_dict.iteritems():
+      if k.startswith(self.getTemplateTypeName()+'/'):
+        new_remove_dict[self._getPath(k)] = v
+    kw['remove_object_dict'] = new_remove_dict
+    BaseTemplateItem.remove(self, context, **kw)
+
   def uninstall(self, context, **kw):
     object_path = kw.get('object_path', None)
     if object_path is not None:
@@ -3667,6 +3690,27 @@ class PropertySheetTemplateItem(Document
       # migrated
       update_parameter_dict[key] = 'migrate'
 
+  def remove(self, context, **kw):
+    """Conversion of magically uniqued paths to real ones"""
+    remove_object_dict = kw.get('remove_object_dict', {})
+    new_remove_dict = dict()
+    for k,v in remove_object_dict.iteritems():
+      if k.startswith(self.getTemplateTypeName()+'/'):
+        new_remove_dict[self._getPath(k)] = v
+    kw['remove_object_dict'] = new_remove_dict
+    ObjectTemplateItem.remove(self, context, **kw)
+
+  def preinstall(self, *args, **kwargs):
+    preinstall_dict = ObjectTemplateItem.preinstall(self, *args, **kwargs)
+    new_preinstall_dict = dict()
+    for k, v in preinstall_dict.iteritems():
+      if not k.startswith('portal_property_sheets/'):
+        # Magical way to have unique path in case of not yet migrated property
+        # sheets available on preinstall list
+        k = self._getKey(k)
+      new_preinstall_dict[k] = v
+    return new_preinstall_dict
+
   def install(self, context, **kw):
     if not self._perform_migration:
       return DocumentTemplateItem.install(self, context, **kw)



More information about the Erp5-report mailing list