From 8c136ea16b20dc005c2dbc8143f5446d5af49eb1 Mon Sep 17 00:00:00 2001 From: helmutm Date: Wed, 19 Dec 2007 07:38:37 +0000 Subject: [PATCH] i18n: don't use default when updating git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@2260 fd906abe-77d9-0310-91a1-e0d9ade77398 --- browser/form.py | 2 +- browser/node.py | 3 ++- i18n/browser.py | 7 ++++++- i18n/common.py | 8 ++++++-- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/browser/form.py b/browser/form.py index e5a3d2c..30bd571 100644 --- a/browser/form.py +++ b/browser/form.py @@ -329,7 +329,7 @@ class EditObject(FormController, I18NView): @Lazy def adapted(self): - return adapted(self.object, self.languageInfo) + return adapted(self.object, self.languageInfoForUpdate) @Lazy def typeInterface(self): diff --git a/browser/node.py b/browser/node.py index 75b3d8d..344205f 100644 --- a/browser/node.py +++ b/browser/node.py @@ -309,7 +309,8 @@ class NodeView(BaseView): obj = self.virtualTargetObject if obj is not None: basicView = zapi.getMultiAdapter((obj, self.request)) - basicView._viewName = self.context.viewName + if obj == self.targetObject: + basicView._viewName = self.context.viewName return basicView.view @Lazy diff --git a/i18n/browser.py b/i18n/browser.py index 983c76e..04cc0ef 100644 --- a/i18n/browser.py +++ b/i18n/browser.py @@ -39,9 +39,10 @@ i18n_macros = ViewPageTemplateFile('i18n_macros.pt') class LanguageInfo(object): - def __init__(self, context, request): + def __init__(self, context, request, allowDefault=True): self.context = context self.request = request + self.allowDefault = allowDefault @Lazy def loopsRoot(self): @@ -76,6 +77,10 @@ class I18NView(object): def languageInfo(self): return LanguageInfo(self.context, self.request) + @Lazy + def languageInfoForUpdate(self): + return LanguageInfo(self.context, self.request, False) + @Lazy def useI18NForEditing(self): return (self.languageInfo.availableLanguages diff --git a/i18n/common.py b/i18n/common.py index e181937..8e608bb 100644 --- a/i18n/common.py +++ b/i18n/common.py @@ -68,20 +68,24 @@ def getI18nValue(obj, attr, langInfo=None): if isinstance(value, I18NValue): if langInfo: result = value.get(langInfo.language, _not_found) - if result is _not_found: + if result is _not_found and langInfo.allowDefault: result = value.get(langInfo.defaultLanguage, _not_found) if result is _not_found: result = value.getDefault() return result else: return value.getDefault() - return value + if langInfo is None or langInfo.allowDefault: + return value + return None def setI18nValue(obj, attr, value, langInfo=None): obj = removeSecurityProxy(obj) old = getattr(obj, attr, None) if langInfo is None: if isinstance(old, I18NValue): + # TODO (?): Just replace the value corresponding to + # that of the default language raise ValueError('Attribute %s on object %s is an I18NValue (%s) ' 'and no langInfo given.' % (attr, obj, value)) else: