[gen] Bugfix: getFormattedValue must produce a different value for strings with format=TEXT depending on the layout type.
This commit is contained in:
parent
a4a9acfcfb
commit
4009cf824c
|
@ -62,7 +62,7 @@ class Field:
|
|||
rawValue=not isSearch and zobj.getFieldValue(name, \
|
||||
layoutType=layoutType, outerValue=outerValue);
|
||||
value=not isSearch and \
|
||||
field.getFormattedValue(zobj, rawValue, showChanges);
|
||||
field.getFormattedValue(zobj,rawValue,layoutType,showChanges);
|
||||
requestValue=not isSearch and zobj.getRequestFieldValue(name);
|
||||
inRequest=field.valueIsInRequest(zobj, req, name, layoutType);
|
||||
error=req.get('%s_error' % name);
|
||||
|
@ -672,7 +672,8 @@ class Field:
|
|||
if this value is mutable, get a copy of it.'''
|
||||
return self.getValue(obj)
|
||||
|
||||
def getFormattedValue(self, obj, value, showChanges=False, language=None):
|
||||
def getFormattedValue(self, obj, value, layoutType='view',
|
||||
showChanges=False, language=None):
|
||||
'''p_value is a real p_obj(ect) value from a field from this type. This
|
||||
method returns a pretty, string-formatted version, for displaying
|
||||
purposes. Needs to be overridden by some child classes. If
|
||||
|
@ -683,12 +684,13 @@ class Field:
|
|||
if self.isEmptyValue(obj, value): return ''
|
||||
return value
|
||||
|
||||
def getShownValue(self, obj, value, showChanges=False, language=None):
|
||||
def getShownValue(self, obj, value, layoutType='view',
|
||||
showChanges=False, language=None):
|
||||
'''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, language)
|
||||
return self.getFormattedValue(obj,value,layoutType,showChanges,language)
|
||||
|
||||
def getXmlValue(self, obj, value):
|
||||
'''This method allows a developer to customize the value that will be
|
||||
|
|
|
@ -117,7 +117,8 @@ class Boolean(Field):
|
|||
return '%s_%s' % (self.labelId, self.trueFalse[value])
|
||||
return self.yesNo[value]
|
||||
|
||||
def getFormattedValue(self, obj, value, showChanges=False, language=None):
|
||||
def getFormattedValue(self, obj, value, layoutType='view',
|
||||
showChanges=False, language=None):
|
||||
return obj.translate(self.getValueLabel(value), language=language)
|
||||
|
||||
def getStorableValue(self, obj, value):
|
||||
|
|
|
@ -93,7 +93,8 @@ class Computed(Field):
|
|||
# self.method is a method that will return the field value
|
||||
return self.callMethod(obj, self.method, cache=False)
|
||||
|
||||
def getFormattedValue(self, obj, value, showChanges=False, language=None):
|
||||
def getFormattedValue(self, obj, value, layoutType='view',
|
||||
showChanges=False, language=None):
|
||||
if self.formatMethod:
|
||||
res = self.formatMethod(obj, value)
|
||||
else:
|
||||
|
|
|
@ -230,7 +230,8 @@ class Date(Field):
|
|||
except DateTime.DateError, ValueError:
|
||||
return obj.translate('bad_date')
|
||||
|
||||
def getFormattedValue(self, obj, value, showChanges=False, language=None):
|
||||
def getFormattedValue(self, obj, value, layoutType='view',
|
||||
showChanges=False, language=None):
|
||||
if self.isEmptyValue(obj, value): return ''
|
||||
tool = obj.getTool().appy()
|
||||
# A problem may occur with some extreme year values. Replace the "year"
|
||||
|
|
|
@ -82,7 +82,8 @@ class Float(Field):
|
|||
sheight, persist, view, xml)
|
||||
self.pythonType = float
|
||||
|
||||
def getFormattedValue(self, obj, value, showChanges=False, language=None):
|
||||
def getFormattedValue(self, obj, value, layoutType='view',
|
||||
showChanges=False, language=None):
|
||||
return sutils.formatNumber(value, sep=self.sep[0],
|
||||
precision=self.precision, tsep=self.tsep)
|
||||
|
||||
|
|
|
@ -71,7 +71,8 @@ class Integer(Field):
|
|||
def getStorableValue(self, obj, value):
|
||||
if not self.isEmptyValue(obj, value): return self.pythonType(value)
|
||||
|
||||
def getFormattedValue(self, obj, value, showChanges=False, language=None):
|
||||
def getFormattedValue(self, obj, value, layoutType='view',
|
||||
showChanges=False, language=None):
|
||||
if self.isEmptyValue(obj, value): return ''
|
||||
return str(value)
|
||||
# ------------------------------------------------------------------------------
|
||||
|
|
|
@ -949,7 +949,8 @@ class Ref(Field):
|
|||
nb = req.has_key(key) and req[key] or req.get('startNumber', 0)
|
||||
return int(nb)
|
||||
|
||||
def getFormattedValue(self, obj, value, showChanges=False, language=None):
|
||||
def getFormattedValue(self, obj, value, layoutType='view',
|
||||
showChanges=False, language=None):
|
||||
return value
|
||||
|
||||
def getIndexType(self): return 'ListIndex'
|
||||
|
|
|
@ -109,12 +109,11 @@ class String(Field):
|
|||
<x if="(fmt != 3) and not isUrl">::value</x>
|
||||
</x>''')
|
||||
|
||||
# pxView part for format String.TEXT.
|
||||
# pxView part for format String.TEXT
|
||||
pxViewText = Px('''
|
||||
<span if="not value" class="smaller">-</span>
|
||||
<x if="value">::zobj.formatText(value, format='html')</x>''')
|
||||
<span if="not value" class="smaller">-</span><x if="value">::value</x>''')
|
||||
|
||||
# pxView part for format String.XHTML.
|
||||
# pxView part for format String.XHTML
|
||||
pxViewRich = Px('''
|
||||
<div if="not mayAjaxEdit" class="xhtml">::value or '-'</div>
|
||||
<x if="mayAjaxEdit" var2="name=lg and ('%s_%s' % (name, lg)) or name">
|
||||
|
@ -188,7 +187,7 @@ class String(Field):
|
|||
mapping=field.getCaptchaChallenge(req.SESSION))
|
||||
</span>''')
|
||||
|
||||
# pxEdit part for formats String.TEXT and String.XHTML.
|
||||
# pxEdit part for formats String.TEXT and String.XHTML
|
||||
pxEditTextArea = Px('''
|
||||
<textarea var="inputId=not lg and name or '%s_%s' % (name, lg)"
|
||||
id=":inputId" name=":inputId" cols=":field.width"
|
||||
|
@ -626,8 +625,8 @@ class String(Field):
|
|||
comparator = HtmlDiff(res, value or '', iMsg, dMsg)
|
||||
return comparator.get()
|
||||
|
||||
def getUnilingualFormattedValue(self, obj, value, showChanges=False,
|
||||
userLanguage=None, language=None):
|
||||
def getUnilingualFormattedValue(self, obj, value, layoutType='view',
|
||||
showChanges=False, userLanguage=None, language=None):
|
||||
'''If no p_language is specified, this method is called by
|
||||
m_getFormattedValue for getting a non-multilingual value (ie, in
|
||||
most cases). Else, this method returns a formatted value for the
|
||||
|
@ -654,22 +653,26 @@ class String(Field):
|
|||
res = _('%s_list_%s' % (self.labelId, value), \
|
||||
language=userLanguage)
|
||||
elif (self.format == String.XHTML) and showChanges:
|
||||
# Compute the successive changes that occurred on p_value.
|
||||
# Compute the successive changes that occurred on p_value
|
||||
res = self.getDiffValue(obj, res, language)
|
||||
elif self.format == String.TEXT:
|
||||
if layoutType != 'edit':
|
||||
res = obj.formatText(res, format='html')
|
||||
# If value starts with a carriage return, add a space; else, it will
|
||||
# be ignored.
|
||||
if isinstance(res, basestring) and \
|
||||
(res.startswith('\n') or res.startswith('\r\n')): res = ' ' + res
|
||||
return res
|
||||
|
||||
def getFormattedValue(self, obj, value, showChanges=False, language=None):
|
||||
def getFormattedValue(self, obj, value, layoutType='view',
|
||||
showChanges=False, language=None):
|
||||
'''Be careful: p_language represents the UI language, while "languages"
|
||||
below represents the content language(s) of this field. p_language
|
||||
can be used, ie, to translate a Selection value.'''
|
||||
languages = self.getAttribute(obj, 'languages')
|
||||
if len(languages) == 1:
|
||||
return self.getUnilingualFormattedValue(obj, value, showChanges,
|
||||
userLanguage=language)
|
||||
return self.getUnilingualFormattedValue(obj, value, layoutType,
|
||||
showChanges, userLanguage=language)
|
||||
# Return the dict of values whose individual, language-specific values
|
||||
# have been formatted via m_getUnilingualFormattedValue.
|
||||
if not value and not showChanges: return value
|
||||
|
@ -677,26 +680,27 @@ class String(Field):
|
|||
for lg in languages:
|
||||
if not value: val = ''
|
||||
else: val = value[lg]
|
||||
res[lg] = self.getUnilingualFormattedValue(obj, val, showChanges,
|
||||
language=lg)
|
||||
res[lg] = self.getUnilingualFormattedValue(obj, val, layoutType,
|
||||
showChanges, language=lg)
|
||||
return res
|
||||
|
||||
def getShownValue(self, obj, value, showChanges=False, language=None):
|
||||
def getShownValue(self, obj, value, layoutType='view',
|
||||
showChanges=False, language=None):
|
||||
'''Be careful: p_language represents the UI language, while "languages"
|
||||
below represents the content language(s) of this field. 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,
|
||||
userLanguage=language)
|
||||
return self.getUnilingualFormattedValue(obj, value, layoutType,
|
||||
showChanges, userLanguage=language)
|
||||
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.
|
||||
lg = obj.getUserLanguage()
|
||||
if lg not in value: lg = languages[0]
|
||||
return self.getUnilingualFormattedValue(obj, value[lg], showChanges,
|
||||
language=lg)
|
||||
return self.getUnilingualFormattedValue(obj, value[lg], layoutType,
|
||||
showChanges, language=lg)
|
||||
|
||||
def extractText(self, value):
|
||||
'''Extracts pure text from XHTML p_value.'''
|
||||
|
|
|
@ -1002,7 +1002,11 @@ class BaseMixin:
|
|||
# Compute common parts
|
||||
cssClass = self.getCssFor('title')
|
||||
# Get the title, with highlighted parts when relevant
|
||||
title = self.getShownValue('title')
|
||||
klass = self.getClass()
|
||||
if hasattr(klass, 'listTitle'):
|
||||
title = klass.listTitle(self.appy(), nav)
|
||||
else:
|
||||
title = self.getShownValue('title')
|
||||
if highlight: title = self.highlight(title)
|
||||
if mode == 'link':
|
||||
inPopup = inPopup or (target.target != '_self')
|
||||
|
@ -1557,23 +1561,22 @@ class BaseMixin:
|
|||
return False
|
||||
if parent.meta_type not in ('Folder', 'Temporary Folder'): return parent
|
||||
|
||||
def getShownValue(self, name='title', language=None):
|
||||
'''Call field.getShownValue on field named p_name.'''
|
||||
def getShownValue(self, name='title', layoutType='view', language=None):
|
||||
'''Call field.getShownValue on field named p_name'''
|
||||
field = self.getAppyType(name)
|
||||
return field.getShownValue(self, field.getValue(self),
|
||||
return field.getShownValue(self, field.getValue(self), layoutType,
|
||||
language=language)
|
||||
|
||||
def getBreadCrumb(self, inPopup=False):
|
||||
'''Gets breadcrumb info about this object and its parents (if it must
|
||||
be shown).'''
|
||||
# Return an empty breadcrumb if it must not be shown.
|
||||
# Return an empty breadcrumb if it must not be shown
|
||||
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=title.getShownValue(self, title.getValue(self)))]
|
||||
# In a popup: limit the breadcrumb to the current object.
|
||||
title=self.getShownValue('title'))]
|
||||
# In a popup, limit the breadcrumb to the current object
|
||||
if inPopup: return res
|
||||
parent = self.getParent()
|
||||
if parent: res = parent.getBreadCrumb() + res
|
||||
|
|
|
@ -150,11 +150,12 @@ class ToolWrapper(AbstractWrapper):
|
|||
</script>''')
|
||||
|
||||
pxLiveSearchResults = Px('''
|
||||
<x var="className=req['className'];
|
||||
klass=ztool.getAppyClass(className);
|
||||
search=ztool.getLiveSearch(klass, req['w_SearchableText']);
|
||||
zobjects=ztool.executeQuery(className, search=search, \
|
||||
maxResults=10).objects">
|
||||
<div var="className=req['className'];
|
||||
klass=ztool.getAppyClass(className);
|
||||
search=ztool.getLiveSearch(klass, req['w_SearchableText']);
|
||||
zobjects=ztool.executeQuery(className, search=search, \
|
||||
maxResults=10).objects"
|
||||
id=":'%s_LSResults' % className">
|
||||
<p if="not zobjects" class="lsNoResult">:_('query_no_result')</p>
|
||||
<div for="zobj in zobjects" style="padding: 3px 5px">
|
||||
<a href=":zobj.absolute_url()"
|
||||
|
@ -167,7 +168,7 @@ class ToolWrapper(AbstractWrapper):
|
|||
onclick=":'document.forms[%s].submit()' % \
|
||||
q('%s_LSForm' % className)">:_('search_results_all') + '...'</a>
|
||||
</div>
|
||||
</x>''')
|
||||
</div>''')
|
||||
|
||||
pxLiveSearch = Px('''
|
||||
<form var="formId='%s_LSForm' % className"
|
||||
|
|
|
@ -44,7 +44,7 @@ class AbstractWrapper(object):
|
|||
<x for="bc in breadcrumb" var2="nb=loop.bc.nb">
|
||||
<img if="nb != 0" src=":url('to')"/>
|
||||
<!-- Display only the title of the current object -->
|
||||
<span if="nb == len(breadcrumb)-1">:bc.title</span>
|
||||
<span if="nb == len(breadcrumb)-1">::bc.title</span>
|
||||
<!-- Display a link for parent objects -->
|
||||
<a if="nb != len(breadcrumb)-1" href=":bc.url">:bc.title</a>
|
||||
</x>
|
||||
|
@ -874,7 +874,7 @@ class AbstractWrapper(object):
|
|||
|
||||
def getField(self, name): return self.o.getAppyType(name)
|
||||
|
||||
def getValue(self, name, formatted=False, language=None):
|
||||
def getValue(self, name, layoutType='view', formatted=False, language=None):
|
||||
'''Gets the possibly p_formatted value of field p_name. If this
|
||||
formatting implies translating something, it will be done in
|
||||
p_language, or in the user language if not specified. If the "shown"
|
||||
|
@ -887,7 +887,7 @@ class AbstractWrapper(object):
|
|||
if not formatted: return val
|
||||
method = (formatted == 'shown') and 'getShownValue' or \
|
||||
'getFormattedValue'
|
||||
return getattr(field, method)(obj, val, language=language)
|
||||
return getattr(field, method)(obj, val, layoutType, language=language)
|
||||
|
||||
def getLabel(self, name, type='field'):
|
||||
'''Gets the translated label of field named p_name. If p_type is
|
||||
|
|
|
@ -714,7 +714,7 @@ class MemoryBuffer(Buffer):
|
|||
evalEntry.expr, e))
|
||||
else:
|
||||
raise EvaluationError(EVAL_EXPR_ERROR % \
|
||||
(evalEntry.expr, Traceback.get(5)))
|
||||
(evalEntry.expr, '\n'+Traceback.get(5)))
|
||||
elif isinstance(evalEntry, Attributes) or \
|
||||
isinstance(evalEntry, Attribute):
|
||||
result.write(evalEntry.evaluate(context))
|
||||
|
|
Loading…
Reference in a new issue