comparison 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
comparison
equal deleted inserted replaced
5066:d2256fcfd81f 5067:e424987d294a
1199 return _HTMLUser(client, classname, nodeid, anonymous) 1199 return _HTMLUser(client, classname, nodeid, anonymous)
1200 else: 1200 else:
1201 return _HTMLItem(client, classname, nodeid, anonymous) 1201 return _HTMLItem(client, classname, nodeid, anonymous)
1202 1202
1203 class HTMLProperty(HTMLInputMixin, HTMLPermissions): 1203 class HTMLProperty(HTMLInputMixin, HTMLPermissions):
1204 """ String, Number, Date, Interval HTMLProperty 1204 """ String, Integer, Number, Date, Interval HTMLProperty
1205 1205
1206 Has useful attributes: 1206 Has useful attributes:
1207 1207
1208 _name the name of the property 1208 _name the name of the property
1209 _value the value of the property if any 1209 _value the value of the property if any
1603 def __float__(self): 1603 def __float__(self):
1604 """ Return a float of me 1604 """ Return a float of me
1605 """ 1605 """
1606 return float(self._value) 1606 return float(self._value)
1607 1607
1608 class IntegerHTMLProperty(HTMLProperty):
1609 def plain(self, escape=0):
1610 """ Render a "plain" representation of the property
1611 """
1612 if not self.is_view_ok():
1613 return self._('[hidden]')
1614
1615 if self._value is None:
1616 return ''
1617
1618 return str(self._value)
1619
1620 def field(self, size=30, **kwargs):
1621 """ Render a form edit field for the property.
1622
1623 If not editable, just display the value via plain().
1624 """
1625 if not self.is_edit_ok():
1626 return self.plain(escape=1)
1627
1628 value = self._value
1629 if value is None:
1630 value = ''
1631
1632 return self.input(name=self._formname, value=value, size=size,
1633 **kwargs)
1634
1635 def __int__(self):
1636 """ Return an int of me
1637 """
1638 return int(self._value)
1639
1608 1640
1609 class BooleanHTMLProperty(HTMLProperty): 1641 class BooleanHTMLProperty(HTMLProperty):
1610 def plain(self, escape=0): 1642 def plain(self, escape=0):
1611 """ Render a "plain" representation of the property 1643 """ Render a "plain" representation of the property
1612 """ 1644 """
2350 2382
2351 # set the propclasses for HTMLItem 2383 # set the propclasses for HTMLItem
2352 propclasses = [ 2384 propclasses = [
2353 (hyperdb.String, StringHTMLProperty), 2385 (hyperdb.String, StringHTMLProperty),
2354 (hyperdb.Number, NumberHTMLProperty), 2386 (hyperdb.Number, NumberHTMLProperty),
2387 (hyperdb.Integer, IntegerHTMLProperty),
2355 (hyperdb.Boolean, BooleanHTMLProperty), 2388 (hyperdb.Boolean, BooleanHTMLProperty),
2356 (hyperdb.Date, DateHTMLProperty), 2389 (hyperdb.Date, DateHTMLProperty),
2357 (hyperdb.Interval, IntervalHTMLProperty), 2390 (hyperdb.Interval, IntervalHTMLProperty),
2358 (hyperdb.Password, PasswordHTMLProperty), 2391 (hyperdb.Password, PasswordHTMLProperty),
2359 (hyperdb.Link, LinkHTMLProperty), 2392 (hyperdb.Link, LinkHTMLProperty),

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