From 93cc175f2923fa51c19b0897db85c154146fda20 Mon Sep 17 00:00:00 2001 From: Yusuke Muraoka <yusuke@nexedi.com> Date: Mon, 17 May 2010 12:38:11 +0000 Subject: [PATCH] fixed a bug #1790 git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@35389 20353a03-c40f-0410-a6d1-a30d3c3de9de --- product/ERP5Type/Accessor/Translation.py | 40 +++++++++++++++++++++++- product/ERP5Type/Utils.py | 10 +++++- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/product/ERP5Type/Accessor/Translation.py b/product/ERP5Type/Accessor/Translation.py index 3ab19c03e3..80506b9f5e 100644 --- a/product/ERP5Type/Accessor/Translation.py +++ b/product/ERP5Type/Accessor/Translation.py @@ -31,7 +31,7 @@ from Products.ERP5Type.PsycoWrapper import psyco from Acquisition import aq_base from Products.CMFCore.utils import getToolByName -from Products.ERP5Type.Accessor.Base import func_code, ATTRIBUTE_PREFIX, evaluateTales, Getter as BaseGetter +from Products.ERP5Type.Accessor.Base import func_code, ATTRIBUTE_PREFIX, evaluateTales, Getter as BaseGetter, Method from Products.ERP5Type.Accessor import Accessor, AcquiredProperty from Products.ERP5Type.Accessor.TypeDefinition import type_definition @@ -217,3 +217,41 @@ class AcquiredPropertyGetter(AcquiredProperty.Getter): return value.getProperty(self._acquired_property, default, **kw) else: return default + +class TranslatedPropertyTester(Method): + """ + Tests if an attribute value exists + """ + _need__name__=1 + + # This is required to call the method form the Web + func_code = func_code() + func_code.co_varnames = ('self',) + func_code.co_argcount = 1 + func_defaults = () + + def __init__(self, id, key, property_id, property_type, language, warning=0): + self._id = id + self.__name__ = id + self._property_id = property_id + self._property_type = property_type + self._null = type_definition[property_type]['null'] + self._language = language + self._warning = warning + + def __call__(self, instance, *args, **kw): + if self._warning: + LOG("ERP5Type Deprecated Tester Id:",0, self._id) + domain = instance.getProperty('%s_translation_domain' % self._property_id) + + if domain==TRANSLATION_DOMAIN_CONTENT_TRANSLATION: + if self._language is None: + language = kw.get('language') or getToolByName(instance, 'Localizer').get_selected_language() + else: + language = self._language + try: + return instance.getPropertyTranslation(self._property_id, language) is not None + except KeyError: + return False + else: + return instance.getProperty(self._property_id) is not None diff --git a/product/ERP5Type/Utils.py b/product/ERP5Type/Utils.py index e52d813ac5..1543ebea7d 100644 --- a/product/ERP5Type/Utils.py +++ b/product/ERP5Type/Utils.py @@ -2853,6 +2853,7 @@ def createTranslationLanguageAccessors(property_holder, property, composed_id = '%s_translated_%s' % (language_key, property['id']) capitalised_compose_id = UpperCase(composed_id) + # get getter_accessor_args = (property['id'], property['type'], language, default) accessor_dict_list.append({'name': 'get' + capitalised_compose_id, 'class': Translation.TranslatedPropertyGetter, @@ -2863,7 +2864,14 @@ def createTranslationLanguageAccessors(property_holder, property, 'argument': getter_accessor_args, 'permission': read_permission}) - setter_accessor_args = (property['id'], property['type'], language) + # has + has_accessor_args = (property['id'], property['type'], language) + accessor_dict_list.append({'name': 'has' + capitalised_compose_id, + 'class': Translation.TranslatedPropertyTester, + 'argument': has_accessor_args, + 'permission': read_permission}) + + # set accessor_dict_list.append({'name':'set' + capitalised_compose_id, 'key': '_set' + capitalised_compose_id, 'class': Alias.Reindex, -- 2.30.9