# HG changeset patch # User Sylvain Thénault # Date 1317910448 -7200 # Node ID fb757a7d887e3a6b14ca2a68df56c558272f4857 # Parent d0c6a7993cec690264c883115ce2d77360057c0d [request, ui] printable_value is now a method of request, and may be given dict of formatters to use (closes #1984743) diff -r d0c6a7993cec -r fb757a7d887e entity.py --- a/entity.py Thu Oct 06 16:14:08 2011 +0200 +++ b/entity.py Thu Oct 06 16:14:08 2011 +0200 @@ -40,7 +40,7 @@ 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 @@ 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 diff -r d0c6a7993cec -r fb757a7d887e req.py --- a/req.py Thu Oct 06 16:14:08 2011 +0200 +++ b/req.py Thu Oct 06 16:14:08 2011 +0200 @@ -29,7 +29,7 @@ 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 @@ 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 diff -r d0c6a7993cec -r fb757a7d887e uilib.py --- a/uilib.py Thu Oct 06 16:14:08 2011 +0200 +++ b/uilib.py Thu Oct 06 16:14:08 2011 +0200 @@ -30,6 +30,7 @@ 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 @@ '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 #############################################################