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