Mercurial > p > roundup > code
diff roundup/cgi/templating.py @ 5067:e424987d294a
Add support for an integer type to join the existing number type.
Commit patch supplied for issue2550886. This can be used for
properties used for ordering, counts etc. where a decimal point
isn't needed. Developed by Anthony (antmail). Doc updates written by
John Rouillard.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Sun, 05 Jun 2016 00:17:26 -0400 |
| parents | 2ac11cc397eb |
| children | c1f1465d5303 |
line wrap: on
line diff
--- a/roundup/cgi/templating.py Tue May 31 09:16:09 2016 +0200 +++ b/roundup/cgi/templating.py Sun Jun 05 00:17:26 2016 -0400 @@ -1201,7 +1201,7 @@ return _HTMLItem(client, classname, nodeid, anonymous) class HTMLProperty(HTMLInputMixin, HTMLPermissions): - """ String, Number, Date, Interval HTMLProperty + """ String, Integer, Number, Date, Interval HTMLProperty Has useful attributes: @@ -1605,6 +1605,38 @@ """ return float(self._value) +class IntegerHTMLProperty(HTMLProperty): + def plain(self, escape=0): + """ Render a "plain" representation of the property + """ + if not self.is_view_ok(): + return self._('[hidden]') + + if self._value is None: + return '' + + return str(self._value) + + def field(self, size=30, **kwargs): + """ Render a form edit field for the property. + + If not editable, just display the value via plain(). + """ + if not self.is_edit_ok(): + return self.plain(escape=1) + + value = self._value + if value is None: + value = '' + + return self.input(name=self._formname, value=value, size=size, + **kwargs) + + def __int__(self): + """ Return an int of me + """ + return int(self._value) + class BooleanHTMLProperty(HTMLProperty): def plain(self, escape=0): @@ -2352,6 +2384,7 @@ propclasses = [ (hyperdb.String, StringHTMLProperty), (hyperdb.Number, NumberHTMLProperty), + (hyperdb.Integer, IntegerHTMLProperty), (hyperdb.Boolean, BooleanHTMLProperty), (hyperdb.Date, DateHTMLProperty), (hyperdb.Interval, IntervalHTMLProperty),
