Exemple #1
0
 def testSignificantFormat(self):
     self.assertEqual(significant_format(2.1), '2.1')
     self.assertEqual(significant_format(2153.2), '2,153')
     self.assertEqual(significant_format(2153.2, n=10), '2,153.2')
     # try with a string
     self.assertEqual(significant_format('-45233.1', n=10), '-45,233.1')
     self.assertEqual(significant_format(123.5), '123.5')
Exemple #2
0
 def testSignificantFormat(self):
     self.assertEqual(significant_format(2.1), '2.1')
     self.assertEqual(significant_format(2153.2), '2,153')
     self.assertEqual(significant_format(2153.2, n=10), '2,153.2')
     # try with a string
     self.assertEqual(significant_format('-45233.1', n=10), '-45,233.1')
     self.assertEqual(significant_format(123.5), '123.5')
Exemple #3
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