[gen] Bugfixes: handle multilingual titles in queries, references, breadcrumbs...

This commit is contained in:
Gaetan Delannay 2014-09-06 15:20:59 +02:00
parent f8a7103c7a
commit 8aed007623
6 changed files with 34 additions and 6 deletions

View file

@ -542,6 +542,13 @@ class Field:
if self.isEmptyValue(obj, value): return '' if self.isEmptyValue(obj, value): return ''
return value 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): def getIndexType(self):
'''Returns the name of the technical, Zope-level index type for this '''Returns the name of the technical, Zope-level index type for this
field.''' field.'''

View file

@ -50,7 +50,7 @@ class Ref(Field):
inPopup=linkInPopup)" inPopup=linkInPopup)"
href=":fullUrl" class=":cssClass" target=":target.target" href=":fullUrl" class=":cssClass" target=":target.target"
onclick=":target.openPopup">:(not includeShownInfo) and \ onclick=":target.openPopup">:(not includeShownInfo) and \
tied.title or field.getReferenceLabel(tied) tied.o.getShownValue('title') or field.getReferenceLabel(tied)
</a><span name="subTitle" style=":showSubTitles and 'display:inline' or \ </a><span name="subTitle" style=":showSubTitles and 'display:inline' or \
'display:none'">::tied.o.getSubTitle()</span></x>''') 'display:none'">::tied.o.getSubTitle()</span></x>''')
@ -1237,7 +1237,7 @@ class Ref(Field):
for fieldName in self.shownInfo: for fieldName in self.shownInfo:
refType = refObject.o.getAppyType(fieldName) refType = refObject.o.getAppyType(fieldName)
value = getattr(refObject, fieldName) value = getattr(refObject, fieldName)
value = refType.getFormattedValue(refObject.o, value) value = refType.getShownValue(refObject.o, value)
if refType.type == 'String': if refType.type == 'String':
if refType.format == 2: if refType.format == 2:
value = self.xhtmlToText.sub(' ', value) value = self.xhtmlToText.sub(' ', value)

View file

@ -632,6 +632,20 @@ class String(Field):
showChanges, lg) showChanges, lg)
return res 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): def extractText(self, value):
'''Extracts pure text from XHTML p_value.''' '''Extracts pure text from XHTML p_value.'''
return XhtmlTextExtractor(raiseOnError=False).parse('<p>%s</p>' % value) return XhtmlTextExtractor(raiseOnError=False).parse('<p>%s</p>' % value)

View file

@ -71,7 +71,8 @@ class Migrator:
'''Executes a migration when relevant, or do it for sure if p_force is '''Executes a migration when relevant, or do it for sure if p_force is
True.''' True.'''
appyVersion = self.tool.appyVersion 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. # Migration is required.
self.logger.info('Appy version (DB) is %s' % appyVersion) self.logger.info('Appy version (DB) is %s' % appyVersion)
startTime = time.time() startTime = time.time()

View file

@ -1298,7 +1298,7 @@ class BaseMixin:
def Title(self): def Title(self):
'''Returns the title for this object.''' '''Returns the title for this object.'''
title = self.getAppyType('title') title = self.getAppyType('title')
if title: return title.getValue(self) if title: return title.getIndexValue(self)
return self.id return self.id
def SortableTitle(self): def SortableTitle(self):
@ -1468,6 +1468,11 @@ class BaseMixin:
return False return False
if parent.meta_type not in ('Folder', 'Temporary Folder'): return parent 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): def getBreadCrumb(self, inPopup=False):
'''Gets breadcrumb info about this object and its parents (if it must '''Gets breadcrumb info about this object and its parents (if it must
be shown).''' be shown).'''
@ -1475,8 +1480,9 @@ class BaseMixin:
klass = self.getClass() klass = self.getClass()
if hasattr(klass, 'breadcrumb') and not klass.breadcrumb: return () if hasattr(klass, 'breadcrumb') and not klass.breadcrumb: return ()
# Compute the breadcrumb # Compute the breadcrumb
title = self.getAppyType('title')
res = [Object(url=self.getUrl(inPopup=inPopup), 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. # In a popup: limit the breadcrumb to the current object.
if inPopup: return res if inPopup: return res
parent = self.getParent() parent = self.getParent()

View file

@ -322,7 +322,7 @@ class ToolWrapper(AbstractWrapper):
var2="linkInPopup=inPopup or (target.target != '_self')" var2="linkInPopup=inPopup or (target.target != '_self')"
target=":target.target" onclick=":target.openPopup" target=":target.target" onclick=":target.openPopup"
href=":zobj.getUrl(nav=navInfo, page=zobj.getDefaultViewPage(), \ href=":zobj.getUrl(nav=navInfo, page=zobj.getDefaultViewPage(), \
inPopup=linkInPopup)">:zobj.Title()</a> inPopup=linkInPopup)">:zobj.getShownValue('title')</a>
<span if="not enableLinks" <span if="not enableLinks"
class=":not checkboxes and cssClass or ('%s clickable' % cssClass)" class=":not checkboxes and cssClass or ('%s clickable' % cssClass)"
onclick=":checkboxes and ('onSelectObject(%s,%s,%s)' % (q(cbId), \ onclick=":checkboxes and ('onSelectObject(%s,%s,%s)' % (q(cbId), \