Example #1
0
def nicerepr(val,
             nd=None,
             none_value=NONE_VALUE,
             dateformat=None,
             timeformat=None,
             settings=None,
             **kwargs):
    '''Prettify a value to be displayed in html.

:parameter val: value to prettify.
:parameter nd: numerical accuracy for floating point numbers.
'''
    if val is None:
        return NONE_VALUE
    elif is_safe(val):
        return val
    elif isinstance(val, date):
        return smart_time(val, dateformat, timeformat, settings)
    elif isinstance(val, bool):
        if val:
            return with_icon('true')
        else:
            return with_icon('false')
    elif hasattr(val, '_meta'):
        return val._meta.name
    else:
        val = to_string(val)
        try:
            return significant_format(val, n=nd)
        except ValueError:
            if val.startswith('http://') or val.startswith('https://'):
                val = mark_safe('<a href="{0}">{0}</a>'.format(val))
            return val
Example #2
0
 def testSmartTime(self):
     t = time.time()
     dte = datetime.fromtimestamp(t)
     self.assertEqual(len(smart_time(t)), 5)
Example #3
0
 def testSmartTime(self):
     t = time.time()
     dte = datetime.fromtimestamp(t)
     self.assertEqual(len(smart_time(t)),5)