[Erp5-report] r30270 - in /erp5/trunk/products/ERP5: Document/ Interactor/ PropertySheet/ t...

nobody at svn.erp5.org nobody at svn.erp5.org
Wed Nov 4 08:23:26 CET 2009


Author: yusei
Date: Wed Nov  4 08:23:26 2009
New Revision: 30270

URL: http://svn.erp5.org?rev=30270&view=rev
Log:
Commit content translation feature and enable it on Person and GeographicAddress.

Added:
    erp5/trunk/products/ERP5/tests/testContentTranslation.py
Modified:
    erp5/trunk/products/ERP5/Document/Person.py
    erp5/trunk/products/ERP5/Interactor/AqDynamicInteractor.py
    erp5/trunk/products/ERP5/PropertySheet/GeographicAddress.py
    erp5/trunk/products/ERP5/PropertySheet/Person.py

Modified: erp5/trunk/products/ERP5/Document/Person.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Document/Person.py?rev=30270&r1=30269&r2=30270&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Document/Person.py [utf8] (original)
+++ erp5/trunk/products/ERP5/Document/Person.py [utf8] Wed Nov  4 08:23:26 2009
@@ -120,6 +120,25 @@
           name_list.append(self.getMiddleName())
         if self.getLastName() not in (None, ''):
           name_list.append(self.getLastName())
+        return ' '.join(name_list)
+      else:
+        return self.title
+
+    security.declareProtected(Permissions.AccessContentsInformation,
+                              'getTranslatedTitle')
+    def getTranslatedTitle(self, **kw):
+      """
+        Returns the title if it exists or a combination of
+        first name and last name
+      """
+      if self.title == '':
+        name_list = []
+        if self.getTranslatedFirstName(**kw) not in (None, ''):
+          name_list.append(self.getTranslatedFirstName(**kw))
+        if self.getTranslatedMiddleName(**kw) not in (None, ''):
+          name_list.append(self.getTranslatedMiddleName(**kw))
+        if self.getTranslatedLastName(**kw) not in (None, ''):
+          name_list.append(self.getTranslatedLastName(**kw))
         return ' '.join(name_list)
       else:
         return self.title

Modified: erp5/trunk/products/ERP5/Interactor/AqDynamicInteractor.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Interactor/AqDynamicInteractor.py?rev=30270&r1=30269&r2=30270&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Interactor/AqDynamicInteractor.py [utf8] (original)
+++ erp5/trunk/products/ERP5/Interactor/AqDynamicInteractor.py [utf8] Wed Nov  4 08:23:26 2009
@@ -47,9 +47,12 @@
     self.on(TransitionDefinition.setProperties).doAfter(self.resetAqDynamic)
     from Products.DCWorkflow.Variables import Variables
     self.on(Variables.setStateVar).doAfter(self.resetAqDynamic)
+    from Products.Localizer.Localizer import Localizer
+    self.on(Localizer.add_language).doAfter(self.resetAqDynamic)
+    self.on(Localizer.del_language).doAfter(self.resetAqDynamic)
 
   def resetAqDynamic(self, *args, **kw):
     """
       Reset _aq_dynamic
     """
-    _aq_reset()
+    _aq_reset()

Modified: erp5/trunk/products/ERP5/PropertySheet/GeographicAddress.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/PropertySheet/GeographicAddress.py?rev=30270&r1=30269&r2=30270&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/PropertySheet/GeographicAddress.py [utf8] (original)
+++ erp5/trunk/products/ERP5/PropertySheet/GeographicAddress.py [utf8] Wed Nov  4 08:23:26 2009
@@ -35,11 +35,17 @@
         {   'id'          : 'street_address',
             'description' : 'Street address.',
             'type'        : 'string',
-            'mode'        : 'w' },
+            'mode'        : 'w',
+            'translatable': True,
+            'translation_domain' : 'content_translation',
+            },
         {   'id'          : 'city',
             'description' : 'City name.',
             'type'        : 'string',
-            'mode'        : 'w' },
+            'mode'        : 'w',
+            'translatable': True,
+            'translation_domain' : 'content_translation',
+            },
         {   'id'          : 'zip_code',
             'description' : 'Zip code.',
             'type'        : 'string',
@@ -47,7 +53,10 @@
         {   'id'          : 'prefecture',
             'description' : 'Prefecture.',
             'type'        : 'string',
-            'mode'        : 'w' },
+            'mode'        : 'w',
+            'translatable': True,
+            'translation_domain' : 'content_translation',
+            },
     )
 
     _categories = ( 'region', )

Modified: erp5/trunk/products/ERP5/PropertySheet/Person.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/PropertySheet/Person.py?rev=30270&r1=30269&r2=30270&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/PropertySheet/Person.py [utf8] (original)
+++ erp5/trunk/products/ERP5/PropertySheet/Person.py [utf8] Wed Nov  4 08:23:26 2009
@@ -39,16 +39,22 @@
     , 'description': 'First name.'
     , 'type'       : 'string'
     , 'mode'       : 'w'
+    , 'translatable' : True
+    , 'translation_domain' : 'content_translation'
     },
     { 'id'         : 'last_name'
     , 'description': 'Last name.'
     , 'type'       : 'string'
     , 'mode'       : 'w'
+    , 'translatable' : True
+    , 'translation_domain' : 'content_translation'
     },
     { 'id'         : 'middle_name'
     , 'description': 'Middle name.'
     , 'type'       : 'string'
     , 'mode'       : 'w'
+    , 'translatable' : True
+    , 'translation_domain' : 'content_translation'
     },
     { 'id'         : 'birth_name'
     , 'description': 'Also called maiden name.'
@@ -77,6 +83,7 @@
     , 'type'                     : 'content'
     , 'portal_type'              : ( 'Address', )
     , 'acquired_property_id'     : ( 'text', 'street_address', 'city',
+                                     'prefecture',
                                      'zip_code', 'region', 'region_title')
     , 'acquisition_copy_value'   : 0
     , 'acquisition_mask_value'   : 1
@@ -107,6 +114,7 @@
     , 'type'                     : 'content'
     , 'portal_type'              : ( 'Address', )
     , 'acquired_property_id'     : ( 'text', 'street_address', 'city',
+                                     'prefecture',
                                      'zip_code', 'region', 'region_title',
                                      'prefecture')
     , 'acquisition_base_category': ( 'subordination', )
@@ -118,6 +126,8 @@
     , 'acquisition_depends'      : None
     , 'alt_accessor_id'          : ( 'getCareerDefaultAddressValue', )
     , 'mode'                     : 'w'
+    , 'translation_acquired_property_id':('street_address', 'city',
+                                          'prefecture', )
     },
     { 'id'                       : 'telephone'
     , 'storage_id'               : 'default_telephone'

Added: erp5/trunk/products/ERP5/tests/testContentTranslation.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/tests/testContentTranslation.py?rev=30270&view=auto
==============================================================================
--- erp5/trunk/products/ERP5/tests/testContentTranslation.py (added)
+++ erp5/trunk/products/ERP5/tests/testContentTranslation.py [utf8] Wed Nov  4 08:23:26 2009
@@ -1,0 +1,119 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# Copyright (c) 2009 Nexedi KK, Nexedi SA and Contributors. All Rights Reserved.
+#
+# WARNING: This program as such is intended to be used by professional
+# programmers who take the whole responsability of assessing all potential
+# consequences resulting from its eventual inadequacies and bugs
+# End users who are looking for a ready-to-use solution with commercial
+# garantees and support are strongly adviced to contract a Free Software
+# Service Company
+#
+# This program is Free Software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+#
+##############################################################################
+import unittest
+from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
+import transaction
+
+
+class TestContentTranslation(ERP5TypeTestCase):
+  """
+  Test Content Translation
+  """
+
+  def getTitle(self):
+    return 'Test Content Translation'
+
+  def getBusinessTemplateList(self):
+
+    return ('erp5_base',
+            'erp5_content_translation',
+            )
+
+  def afterSetUp(self):
+    return
+
+  def testContentTranslation(self):
+    """
+    Make sure that translatable properties can have content translation into
+    the document and read/write translation text by special accessors.
+    """
+    portal = self.portal
+    person = portal.person_module.newContent(id='yusei',
+                                             portal_type='Person',
+                                             first_name='Yusei',
+                                             last_name='Tahara')
+    portal.person_module.newContent(id='tarou',
+                                    portal_type='Person',
+                                    first_name='Tarou',
+                                    last_name='Suzuki')
+    portal.person_module.newContent(id='john',
+                                    portal_type='Person',
+                                    first_name='John',
+                                    last_name='Smith')
+    transaction.commit()
+    self.tic()
+
+    self.assertEqual(getattr(person, 'setJaKanaTranslatedFirstName', False),
+                     False)
+    self.assertEqual(getattr(person, 'getJaKanaTranslatedFirstName', False),
+                     False)
+    self.assert_(getattr(person, 'getEnTranslatedFirstName', False))
+    self.assert_(getattr(person, 'getEnTranslatedFirstName', False))
+
+    portal.Localizer._add_user_defined_language('Japanese Kana', 'ja-kana')
+    portal.Localizer.add_language('ja-kana')
+    transaction.commit()
+    self.tic()
+
+    self.assert_(getattr(person, 'setJaKanaTranslatedFirstName', False))
+    self.assert_(getattr(person, 'getJaKanaTranslatedFirstName', False))
+
+    person.setJaKanaTranslatedFirstName('タハラ')
+    person.setJaKanaTranslatedLastName('ユウセイ')
+
+    transaction.commit()
+    self.tic()
+
+    self.assert_('タハラ' in person.Base_viewContentTranslation())
+    self.assert_('ユウセイ' in person.Base_viewContentTranslation())
+
+    self.assertEqual(person.getJaKanaTranslatedFirstName(), 'タハラ')
+    self.assertEqual(person.getJaKanaTranslatedLastName(), 'ユウセイ')
+    self.assertEqual(person.getTranslatedTitle(language='ja-kana'),
+                     'タハラ ユウセイ')
+
+    # check with acquisition
+    self.assertEquals(person.getAddress(), None)
+    
+    person.setDefaultAddressStreetAddress('Taito-ku Tokyo')
+    self.assertEquals(person.getDefaultAddressStreetAddress(), 'Taito-ku Tokyo')
+
+    person.setDefaultAddressJaKanaTranslatedStreetAddress('東京都 台東区')
+    self.assertEquals(person.getDefaultAddressJaKanaTranslatedStreetAddress(), '東京都 台東区')
+    self.assertEquals(person.getDefaultAddressTranslatedStreetAddress(language='ja-kana'), '東京都 台東区')
+
+    # check acquired target
+    address = person.getDefaultAddress()
+    self.assertEquals(address.getStreetAddress(), 'Taito-ku Tokyo')
+    self.assertEquals(address.getJaKanaTranslatedStreetAddress(), '東京都 台東区')
+    self.assertEquals(address.getTranslatedStreetAddress(language='ja-kana'), '東京都 台東区')
+
+def test_suite():
+  suite = unittest.TestSuite()
+  suite.addTest(unittest.makeSuite(TestContentTranslation))
+  return suite




More information about the Erp5-report mailing list