i18n: don't use default when updating
git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@2260 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
c03bd7e8ac
commit
8c136ea16b
4 changed files with 15 additions and 5 deletions
|
@ -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):
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Add table
Reference in a new issue