Mercurial > p > roundup > code
diff roundup/cgi/templating.py @ 6292:1e5ed659e8ca issue2550923_computed_property
Initial implementation of Computed property
It supports query/display in html, rest and xml interfaces.
You can specify a cache parameter, but using it raises
NotImplementedError.
It does not support: search, sort or grouping by the computed field.
Checking in on a branch to get more eyeballs on it and maybe some
people to help.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Fri, 27 Nov 2020 18:09:00 -0500 |
| parents | 3f7538316724 |
| children | 1a15089c2e49 |
line wrap: on
line diff
--- a/roundup/cgi/templating.py Fri Nov 27 17:55:52 2020 -0500 +++ b/roundup/cgi/templating.py Fri Nov 27 18:09:00 2020 -0500 @@ -1882,6 +1882,33 @@ value = html_escape(value) return value +class ComputedHTMLProperty(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 '' + try: + if isinstance(self._value, str): + value = self._value + else: + value = str(self._value) + + except AttributeError: + value = self._('[hidden]') + if escape: + value = html_escape(value) + return value + + def field(self): + """ Computed properties are not editable so + just display the value via plain(). + """ + return self.plain(escape=1) + class PasswordHTMLProperty(HTMLProperty): def plain(self, escape=0): """ Render a "plain" representation of the property @@ -2768,6 +2795,7 @@ (hyperdb.Boolean, BooleanHTMLProperty), (hyperdb.Date, DateHTMLProperty), (hyperdb.Interval, IntervalHTMLProperty), + (hyperdb.Computed, ComputedHTMLProperty), (hyperdb.Password, PasswordHTMLProperty), (hyperdb.Link, LinkHTMLProperty), (hyperdb.Multilink, MultilinkHTMLProperty),
