Commit 7d82481f authored by Jérome Perrin's avatar Jérome Perrin

Implement a getTranslatedId method to display translation of meaningfull IDs...

Implement a getTranslatedId method to display translation of meaningfull IDs like "default_address" or "default_career".



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@15891 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent b9bce316
......@@ -869,10 +869,19 @@ class TestHR(ERP5TypeTestCase):
# asURL method works on email
pers = self.getPersonModule().newContent(portal_type='Person')
pers.setDefaultEmailText('nobody@example.com')
email = per.getDefaultEmailValue()
email = pers.getDefaultEmailValue()
self.assertEquals('mailto:nobody@example.com', email.asURL())
def test_getTranslatedId(self):
pers = self.getPersonModule().newContent(
portal_type='Person', id='default_email')
self.assertEquals(None, pers.getTranslatedId())
pers.setDefaultEmailText('nobody@example.com')
email = pers.getDefaultEmailValue()
self.assertEquals('Default Email', str(email.getTranslatedId()))
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestHR))
......
......@@ -66,6 +66,7 @@ from Errors import DeferredCatalogError
from Products.CMFActivity.ActiveObject import ActiveObject
from Products.ERP5Type.Accessor.Accessor import Accessor as Method
from Products.ERP5Type.Accessor.TypeDefinition import asDate
from Products.ERP5Type.Message import Message
from string import join
import sys, re
......@@ -2126,6 +2127,43 @@ class Base( CopyContainer,
return title
return self.getId()
security.declarePublic('getIdTranslationDict')
def getIdTranslationDict(self):
"""Returns the mapping which is used to translate IDs.
"""
return {
'Address': dict(default_address='Default Address'),
'Telephone': dict(default_telephone='Default Telephone',
mobile_telephone='Mobile Telephone',),
'Fax': dict(default_fax='Default Fax'),
'Email': dict(default_email='Default Email',
alternate_email='Alternate Email'),
'Career': dict(default_career='Default Career'),
'Payment Condition': dict(default_payment_condition=
'Default Payment Condition'),
'Image': dict(default_image='Default Image'),
'Purchase Supply Line': dict(purchase_supply_line=
'Default Purchase Supply Line'),
'Sale Supply Line': dict(sale_supply_line=
'Default Sale Supply Line'),
}
security.declareProtected(Permissions.AccessContentsInformation,
'getTranslatedId')
def getTranslatedId(self):
"""Returns the translated ID, if the ID of the current document has a
special meaning, otherwise returns None.
"""
global_translation_dict = self.getIdTranslationDict()
ptype_translation_dict = global_translation_dict.get(
self.portal_type, None)
if ptype_translation_dict is not None:
id_ = self.getId()
if id_ in ptype_translation_dict:
return Message('erp5_ui', ptype_translation_dict[id_])
security.declareProtected(Permissions.AccessContentsInformation,
'getCompactTitle')
def getCompactTitle(self):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment