diff --git a/fields/__init__.py b/fields/__init__.py index 9432ffb..246ce52 100644 --- a/fields/__init__.py +++ b/fields/__init__.py @@ -542,6 +542,13 @@ class Field: if self.isEmptyValue(obj, value): return '' return value + def getShownValue(self, obj, value, showChanges=False): + '''Similar to m_getFormattedValue, but in some contexts, only a part of + p_value must be shown. For example, sometimes we need to display only + a language-specific part of a multilingual field (see overridden + method in string.py).''' + return self.getFormattedValue(obj, value, showChanges) + def getIndexType(self): '''Returns the name of the technical, Zope-level index type for this field.''' diff --git a/fields/ref.py b/fields/ref.py index f3f3a3d..dcf9b78 100644 --- a/fields/ref.py +++ b/fields/ref.py @@ -50,7 +50,7 @@ class Ref(Field): inPopup=linkInPopup)" href=":fullUrl" class=":cssClass" target=":target.target" onclick=":target.openPopup">:(not includeShownInfo) and \ - tied.title or field.getReferenceLabel(tied) + tied.o.getShownValue('title') or field.getReferenceLabel(tied) ::tied.o.getSubTitle()''') @@ -1237,7 +1237,7 @@ class Ref(Field): for fieldName in self.shownInfo: refType = refObject.o.getAppyType(fieldName) value = getattr(refObject, fieldName) - value = refType.getFormattedValue(refObject.o, value) + value = refType.getShownValue(refObject.o, value) if refType.type == 'String': if refType.format == 2: value = self.xhtmlToText.sub(' ', value) diff --git a/fields/string.py b/fields/string.py index 6bbe202..713b321 100644 --- a/fields/string.py +++ b/fields/string.py @@ -632,6 +632,20 @@ class String(Field): showChanges, lg) return res + def getShownValue(self, obj, value, showChanges=False): + '''For a multilingual field, this method only shows one specific + language part.''' + languages = self.getAttribute(obj, 'languages') + if len(languages) == 1: + return self.getUnilingualFormattedValue(obj, value, showChanges) + if not value: return value + # Try to propose the part that is in the user language, or the part of + # the first content language else. + language = obj.getUserLanguage() + if language not in value: language = languages[0] + return self.getUnilingualFormattedValue(obj, value[language], + showChanges, language) + def extractText(self, value): '''Extracts pure text from XHTML p_value.''' return XhtmlTextExtractor(raiseOnError=False).parse('

%s

' % value) diff --git a/gen/migrator.py b/gen/migrator.py index e4954c5..967e701 100644 --- a/gen/migrator.py +++ b/gen/migrator.py @@ -71,7 +71,8 @@ class Migrator: '''Executes a migration when relevant, or do it for sure if p_force is True.''' appyVersion = self.tool.appyVersion - if force or not appyVersion or (appyVersion < '0.9.0'): + # appyVersion being None simply means that we are creating a new DB. + if force or (appyVersion and (appyVersion < '0.9.0')): # Migration is required. self.logger.info('Appy version (DB) is %s' % appyVersion) startTime = time.time() diff --git a/gen/mixins/__init__.py b/gen/mixins/__init__.py index def9d4f..2c5e9cb 100644 --- a/gen/mixins/__init__.py +++ b/gen/mixins/__init__.py @@ -1298,7 +1298,7 @@ class BaseMixin: def Title(self): '''Returns the title for this object.''' title = self.getAppyType('title') - if title: return title.getValue(self) + if title: return title.getIndexValue(self) return self.id def SortableTitle(self): @@ -1468,6 +1468,11 @@ class BaseMixin: return False if parent.meta_type not in ('Folder', 'Temporary Folder'): return parent + def getShownValue(self, name): + '''Call field.getShownValue on field named p_name.''' + field = self.getAppyType('title') + return field.getShownValue(self, field.getValue(self)) + def getBreadCrumb(self, inPopup=False): '''Gets breadcrumb info about this object and its parents (if it must be shown).''' @@ -1475,8 +1480,9 @@ class BaseMixin: klass = self.getClass() if hasattr(klass, 'breadcrumb') and not klass.breadcrumb: return () # Compute the breadcrumb + title = self.getAppyType('title') res = [Object(url=self.getUrl(inPopup=inPopup), - title=self.getFieldValue('title', layoutType='view'))] + title=title.getShownValue(self, title.getValue(self)))] # In a popup: limit the breadcrumb to the current object. if inPopup: return res parent = self.getParent() diff --git a/gen/wrappers/ToolWrapper.py b/gen/wrappers/ToolWrapper.py index 55594ca..4df33b9 100644 --- a/gen/wrappers/ToolWrapper.py +++ b/gen/wrappers/ToolWrapper.py @@ -322,7 +322,7 @@ class ToolWrapper(AbstractWrapper): var2="linkInPopup=inPopup or (target.target != '_self')" target=":target.target" onclick=":target.openPopup" href=":zobj.getUrl(nav=navInfo, page=zobj.getDefaultViewPage(), \ - inPopup=linkInPopup)">:zobj.Title() + inPopup=linkInPopup)">:zobj.getShownValue('title')