Commit 3ba47492 authored by Jérome Perrin's avatar Jérome Perrin

Store orginial key (ie. title if key is translated_title) in the

constructor, to prevent unnecessary computations.



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@7147 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 285ef436
......@@ -26,24 +26,12 @@
#
##############################################################################
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):
"""
Get the translated property
......@@ -60,19 +48,20 @@ class TranslatedPropertyGetter(Method):
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 @@ class PropertyTranslationDomainGetter(Method):
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 @@ class PropertyTranslationDomainGetter(Method):
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
......
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