SVN: GenericSetup/trunk/ - fixed import of the 'i18n_domain' property

Yvo Schubbe <[email protected]> Fri, 10 Feb 2006 10:52:18 -0500 (EST)
Newsgroups gmane.comp.web.zope.public-cvs
Message-ID <[email protected]>
Log message for revision 41591:
  - fixed import of the 'i18n_domain' property
  - made sure objects are moved to the specified position if they existed already above

Changed:
  U   GenericSetup/trunk/tests/test_utils.py
  U   GenericSetup/trunk/utils.py

-=-
Modified: GenericSetup/trunk/tests/test_utils.py
===================================================================
--- GenericSetup/trunk/tests/test_utils.py	2006-02-10 12:26:12 UTC (rev 41590)
+++ GenericSetup/trunk/tests/test_utils.py	2006-02-10 15:52:17 UTC (rev 41591)
@@ -119,6 +119,14 @@
 </dummy>
 """
 
+_I18N_IMPORT = """\
+<?xml version="1.0"?>
+<dummy xmlns:i18n="http://xml.zope.org/namespaces/i18n"
+   i18n:domain="dummy_domain">
+ <property name="foo_string" i18n:translate="">Foo String</property>
+</dummy>
+"""
+
 _NOPURGE_IMPORT = """\
 <?xml version="1.0"?>
 <dummy>
@@ -339,6 +347,13 @@
 
         self.assertEqual(doc.toprettyxml(' '), _EMPTY_PROPERTY_EXPORT)
 
+    def test__initProperties_i18n(self):
+        self.helpers.context.manage_addProperty('i18n_domain', '', 'string')
+        node = parseString(_I18N_IMPORT).documentElement
+        self.helpers._initProperties(node)
+
+        self.assertEqual(self.helpers.context.i18n_domain, 'dummy_domain')
+
     def test__initProperties_nopurge_base(self):
         node = parseString(_NOPURGE_IMPORT).documentElement
         self.helpers.environ._should_purge = True # base profile

Modified: GenericSetup/trunk/utils.py
===================================================================
--- GenericSetup/trunk/utils.py	2006-02-10 12:26:12 UTC (rev 41590)
+++ GenericSetup/trunk/utils.py	2006-02-10 15:52:17 UTC (rev 41591)
@@ -565,6 +565,8 @@
                 else:
                     try:
                         position = parent.getObjectPosition(insert_before)
+                        if parent.getObjectPosition(obj_id) < position:
+                            position -= 1
                         parent.moveObjectToPosition(obj_id, position)
                     except ValueError:
                         pass
@@ -575,6 +577,8 @@
                 else:
                     try:
                         position = parent.getObjectPosition(insert_after)
+                        if parent.getObjectPosition(obj_id) < position:
+                            position -= 1
                         parent.moveObjectToPosition(obj_id, position+1)
                     except ValueError:
                         pass
@@ -652,11 +656,13 @@
                 self.context._updateProperty(prop_id, prop_value)
 
     def _initProperties(self, node):
-        self.context.i18n_domain = node.getAttribute('i18n:domain')
+        obj = self.context
+        if node.hasAttribute('i18n:domain'):
+            i18n_domain = str(node.getAttribute('i18n:domain'))
+            obj._updateProperty('i18n_domain', i18n_domain)
         for child in node.childNodes:
             if child.nodeName != 'property':
                 continue
-            obj = self.context
             prop_id = str(child.getAttribute('name'))
             prop_map = obj.propdict().get(prop_id, None)
 

_______________________________________________
Zope-CVS maillist  -  [email protected]
http://mail.zope.org/mailman/listinfo/zope-cvs

Zope CVS instructions: http://dev.zope.org/CVS