Mercurial > p > roundup > code
comparison roundup/cgi/templating.py @ 8289:46886073c665
refactor: change method used to assign radiobuttons for boolean
use setdefault('type', 'radiobutton') rather than hardcoding the value
into the underlying self.input (input_html4) call.
Also add test for undefined radiobutton.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Sat, 18 Jan 2025 17:43:08 -0500 |
| parents | 6445e63bb423 |
| children | ae7fadcac9e1 |
comparison
equal
deleted
inserted
replaced
| 8288:e70dc7c43c9c | 8289:46886073c665 |
|---|---|
| 2163 self._formname, 'no') | 2163 self._formname, 'no') |
| 2164 n_label += self._('No') | 2164 n_label += self._('No') |
| 2165 n_label += '</label>' | 2165 n_label += '</label>' |
| 2166 | 2166 |
| 2167 checked = value and "checked" or "" | 2167 checked = value and "checked" or "" |
| 2168 kwargs.setdefault("type", "radio") | |
| 2168 if value: | 2169 if value: |
| 2169 y_rb = self.input(type="radio", name=self._formname, value="yes", | 2170 y_rb = self.input(name=self._formname, value="yes", |
| 2170 checked="checked", id="%s_%s" % ( | 2171 checked="checked", id="%s_%s" % ( |
| 2171 self._formname, 'yes'), **kwargs) | 2172 self._formname, 'yes'), **kwargs) |
| 2172 | 2173 |
| 2173 n_rb = self.input(type="radio", name=self._formname, value="no", | 2174 n_rb = self.input(name=self._formname, value="no", |
| 2174 id="%s_%s" % ( | 2175 id="%s_%s" % ( |
| 2175 self._formname, 'no'), **kwargs) | 2176 self._formname, 'no'), **kwargs) |
| 2176 else: | 2177 else: |
| 2177 y_rb = self.input(type="radio", name=self._formname, value="yes", | 2178 y_rb = self.input(name=self._formname, value="yes", |
| 2178 id="%s_%s" % (self._formname, 'yes'), **kwargs) | 2179 id="%s_%s" % (self._formname, 'yes'), **kwargs) |
| 2179 | 2180 |
| 2180 n_rb = self.input(type="radio", name=self._formname, value="no", | 2181 n_rb = self.input(name=self._formname, value="no", |
| 2181 checked="checked", id="%s_%s" % ( | 2182 checked="checked", id="%s_%s" % ( |
| 2182 self._formname, 'no'), **kwargs) | 2183 self._formname, 'no'), **kwargs) |
| 2183 | 2184 |
| 2184 if (u_label): | 2185 if (u_label): |
| 2185 if (u_label is True): # it was set via u_label=True | 2186 if (u_label is True): # it was set via u_label=True |
| 2186 u_label = '' # make it empty but a string not boolean | 2187 u_label = '' # make it empty but a string not boolean |
| 2187 u_rb = self.input(type="radio", name=self._formname, value="", | 2188 u_rb = self.input(name=self._formname, value="", |
| 2188 id="%s_%s" % (self._formname, 'unk'), **kwargs) | 2189 id="%s_%s" % (self._formname, 'unk'), **kwargs) |
| 2189 else: | 2190 else: |
| 2190 # don't generate a trivalue radiobutton. | 2191 # don't generate a trivalue radiobutton. |
| 2191 u_label = '' | 2192 u_label = '' |
| 2192 u_rb = '' | 2193 u_rb = '' |
