Commit a7cbce4e authored by Sylvain Thénault's avatar Sylvain Thénault
Browse files

[request, ui] printable_value is now a method of request, and may be given...

[request, ui] printable_value is now a method of request, and may be given dict of formatters to use (closes #1984743)
parent d0c6a7993cec
......@@ -40,7 +40,7 @@ from cubicweb.req import _check_cw_unsafe
from cubicweb.schema import RQLVocabularyConstraint, RQLConstraint
from cubicweb.rqlrewrite import RQLRewriter
from cubicweb.uilib import printable_value, soup2xhtml
from cubicweb.uilib import soup2xhtml
from cubicweb.mixins import MI_REL_TRIGGERS
from cubicweb.mttransforms import ENGINE
......@@ -619,8 +619,8 @@ class Entity(AppObject):
return self._cw_mtc_transform(value.getvalue(), attrformat, format,
encoding)
return u''
value = printable_value(self._cw, attrtype, value, props,
displaytime=displaytime)
value = self._cw.printable_value(attrtype, value, props,
displaytime=displaytime)
if format == 'text/html':
value = xml_escape(value)
return value
......
......@@ -29,7 +29,7 @@ from logilab.common.decorators import cached
from logilab.common.deprecation import deprecated
from logilab.common.date import ustrftime, strptime, todate, todatetime
from cubicweb import Unauthorized, NoSelectableObject, typed_eid
from cubicweb import Unauthorized, NoSelectableObject, typed_eid, uilib
from cubicweb.rset import ResultSet
ONESECOND = timedelta(0, 1, 0)
......@@ -343,6 +343,18 @@ class RequestSessionBase(object):
rset=rset, **initargs)
return view.render(w=w, **kwargs)
def printable_value(self, attrtype, value, props=None, displaytime=True,
formatters=uilib.PRINTERS):
"""return a displayablye value (i.e. unicode string)"""
if value is None:
return u''
try:
as_string = formatters[attrtype]
except KeyError:
self.error('given bad attrtype %s', attrtype)
return unicode(value)
return as_string(value, self, props, displaytime)
def format_date(self, date, date_format=None, time=False):
"""return a string for a date time according to instance's
configuration
......
......@@ -30,6 +30,7 @@ from StringIO import StringIO
from logilab.mtconverter import xml_escape, html_unescape
from logilab.common.date import ustrftime
from logilab.common.deprecation import deprecated
from cubicweb.utils import JSString, json_dumps
......@@ -134,15 +135,9 @@ PRINTERS = {
'Interval': print_timedelta,
}
@deprecated('[3.14] use req.printable_value(attrtype, value, ...)')
def printable_value(req, attrtype, value, props=None, displaytime=True):
"""return a displayable value (i.e. unicode string)"""
if value is None:
return u''
try:
printer = PRINTERS[attrtype]
except KeyError:
return unicode(value)
return printer(value, req, props, displaytime)
return req.printable_value(attrtype, value, props, displaytime)
# text publishing #############################################################
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment