@@ -1604,10 +1604,21 @@ def plain(self, escape=0):
16041604 return ''
16051605 return self ._value and self ._ ("Yes" ) or self ._ ("No" )
16061606
1607- def field (self , ** kwargs ):
1607+ def field (self , labelfirst = False , y_label = None , n_label = None ,
1608+ u_label = None , ** kwargs ):
16081609 """ Render a form edit field for the property
16091610
16101611 If not editable, just display the value via plain().
1612+
1613+ In addition to being able to set arbitrary html properties
1614+ using prop=val arguments, the thre arguments:
1615+
1616+ y_label, n_label, u_label let you control the labels
1617+ associated with the yes, no (and optionally unknown/empty)
1618+ values.
1619+
1620+ Also the labels can be placed before the radiobuttons by setting
1621+ labelfirst=True.
16111622 """
16121623 if not self .is_edit_ok ():
16131624 return self .plain (escape = 1 )
@@ -1617,21 +1628,45 @@ def field(self, **kwargs):
16171628 value = value .strip ().lower () in ('checked' , 'yes' , 'true' ,
16181629 'on' , '1' )
16191630
1631+ if ( not y_label ):
1632+ y_label = '<label class="rblabel" for="%s_%s">' % (self ._formname , 'yes' )
1633+ y_label += self ._ ('Yes' )
1634+ y_label += '</label>'
1635+
1636+ if ( not n_label ):
1637+ n_label = '<label class="rblabel" for="%s_%s">' % (self ._formname , 'no' )
1638+ n_label += self ._ ('No' )
1639+ n_label += '</label>'
1640+
16201641 checked = value and "checked" or ""
16211642 if value :
1622- s = self .input (type = "radio" , name = self ._formname , value = "yes" ,
1623- checked = "checked" , ** kwargs )
1624- s += self ._ ('Yes' )
1625- s += self .input (type = "radio" , name = self ._formname , value = "no" ,
1626- ** kwargs )
1627- s += self ._ ('No' )
1643+ y_rb = self .input (type = "radio" , name = self ._formname , value = "yes" ,
1644+ checked = "checked" , id = "%s_%s" % (self ._formname , 'yes' ), ** kwargs )
1645+
1646+ n_rb = self .input (type = "radio" , name = self ._formname , value = "no" ,
1647+ id = "%s_%s" % (self ._formname , 'no' ), ** kwargs )
1648+ else :
1649+ y_rb = self .input (type = "radio" , name = self ._formname , value = "yes" ,
1650+ id = "%s_%s" % (self ._formname , 'yes' ), ** kwargs )
1651+
1652+ n_rb = self .input (type = "radio" , name = self ._formname , value = "no" ,
1653+ checked = "checked" , id = "%s_%s" % (self ._formname , 'no' ), ** kwargs )
1654+
1655+ if ( u_label ):
1656+ if (u_label is True ): # it was set via u_label=True
1657+ u_label = '' # make it empty but a string not boolean
1658+ u_rb = self .input (type = "radio" , name = self ._formname , value = "" ,
1659+ id = "%s_%s" % (self ._formname , 'unk' ), ** kwargs )
1660+ else :
1661+ # don't generate a trivalue radiobutton.
1662+ u_label = ''
1663+ u_rb = ''
1664+
1665+ if ( labelfirst ):
1666+ s = u_label + u_rb + y_label + y_rb + n_label + n_rb
16281667 else :
1629- s = self .input (type = "radio" , name = self ._formname , value = "yes" ,
1630- ** kwargs )
1631- s += self ._ ('Yes' )
1632- s += self .input (type = "radio" , name = self ._formname , value = "no" ,
1633- checked = "checked" , ** kwargs )
1634- s += self ._ ('No' )
1668+ s = u_label + u_rb + y_rb + y_label + n_rb + n_label
1669+
16351670 return s
16361671
16371672class DateHTMLProperty (HTMLProperty ):
0 commit comments