comparison roundup/cgi/templating.py @ 6832:234fefd7568a

issue2550559 - Pretty printing / formatting for Number types. add pretty(format='%0.3f') method to NumberHTMLProperty.
author John Rouillard <rouilj@ieee.org>
date Tue, 16 Aug 2022 22:39:04 -0400
parents fe0091279f50
children c27276e0bdce
comparison
equal deleted inserted replaced
6831:e0b29e3fe995 6832:234fefd7568a
1955 if self._value is None: 1955 if self._value is None:
1956 return '' 1956 return ''
1957 1957
1958 return str(self._value) 1958 return str(self._value)
1959 1959
1960 def pretty(self, format="%0.3f"):
1961 '''Pretty print number using printf format specifier.
1962
1963 If value is not convertable, returns str(_value) or ""
1964 if None.
1965 '''
1966 try:
1967 return format%self._value
1968 except TypeError:
1969 value = self._value
1970 if value is None:
1971 return ''
1972 else:
1973 return str(value)
1974
1960 def field(self, size=30, **kwargs): 1975 def field(self, size=30, **kwargs):
1961 """ Render a form edit field for the property. 1976 """ Render a form edit field for the property.
1962 1977
1963 If not editable, just display the value via plain(). 1978 If not editable, just display the value via plain().
1964 """ 1979 """

Roundup Issue Tracker: http://roundup-tracker.org/