[Erp5-report] r7147 - /erp5/trunk/products/ERP5Type/Accessor/Translation.py
nobody at svn.erp5.org
nobody at svn.erp5.org
Wed May 10 14:30:21 CEST 2006
Author: jerome
Date: Wed May 10 14:30:17 2006
New Revision: 7147
URL: http://svn.erp5.org?rev=7147&view=rev
Log:
Store orginial key (ie. title if key is translated_title) in the
constructor, to prevent unnecessary computations.
Modified:
erp5/trunk/products/ERP5Type/Accessor/Translation.py
Modified: erp5/trunk/products/ERP5Type/Accessor/Translation.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/Accessor/Translation.py?rev=7147&r1=7146&r2=7147&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/Accessor/Translation.py (original)
+++ erp5/trunk/products/ERP5Type/Accessor/Translation.py Wed May 10 14:30:17 2006
@@ -26,23 +26,11 @@
#
##############################################################################
-from Base import func_code, type_definition, list_types, ATTRIBUTE_PREFIX, Method
+from Base import func_code, ATTRIBUTE_PREFIX, Method, evaluateTales
from zLOG import LOG
from Products.ERP5Type.PsycoWrapper import psyco
-from string import lower
from Acquisition import aq_base
-from Products.ERP5Type.Cache import CachingMethod
from Products.CMFCore.utils import getToolByName
-
-from Products.CMFCore.Expression import Expression
-def _evaluateTales(instance=None, value=None):
- from Products.ERP5Type.Utils import createExpressionContext
- expression = Expression(value)
- econtext = createExpressionContext(instance)
- return expression(econtext)
-
-evaluateTales = CachingMethod(_evaluateTales, id = 'evaluateTales', cache_duration=300)
-
class TranslatedPropertyGetter(Method):
"""
@@ -60,19 +48,20 @@
self._id = id
self.__name__ = id
self._key = key
+ self._original_key = key.replace('translated_', '')
self._warning = warning
def __call__(self, instance, *args, **kw):
if self._warning:
LOG("ERP5Type Deprecated Getter Id:",0, self._id)
- prop = self._id[13:]
- domain_getter_name = "get%sTranslationDomain" %(prop)
- domain_getter = getattr(instance, domain_getter_name)
- domain = domain_getter()
+ domain = instance.getProperty('%s_translation_domain' %
+ self._original_key)
if domain == '':
return instance.getTitle()
localizer = getToolByName(instance, 'Localizer')
- return localizer[domain].gettext(unicode(instance.getTitle(), 'utf8')).encode('utf8')
+ return localizer[domain].gettext(
+ unicode(instance.getTitle(), 'utf8')
+ ).encode('utf8')
psyco.bind(__call__)
@@ -93,6 +82,7 @@
self._id = id
self.__name__ = id
self._key = key
+ self._original_key = key.replace('_translation_domain', '')
self._property_type = property_type
self._default = default
if storage_id is None:
@@ -105,14 +95,16 @@
default = args[0]
else:
default = self._default
- value = getattr(aq_base(instance), self._storage_id, None) # No acquisition on properties
+ # No acquisition on properties
+ value = getattr(aq_base(instance), self._storage_id, None)
if value is None:
# second try to get it from portal type
- prop_name = self._id[3:-17]
ptype_domain = None
ptype = instance.getPortalType()
ptypes_tool = instance.getPortalObject()['portal_types']
- ptype_domain = ptypes_tool[ptype].getPropertyTranslationDomainDict()[lower(prop_name)].getDomainName()
+ ptype_domain = ptypes_tool[ptype]\
+ .getPropertyTranslationDomainDict()\
+ [self._original_key].getDomainName()
if ptype_domain is '' and default is not None:
# then get the default property defined on property sheet
value = default
More information about the Erp5-report
mailing list