Coverage for khufu/forms/radio.py : 75%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# encoding: utf-8
2from . import *
4def radio(
5 optionText="",
6 optionNumber=1,
7 htmlId=False,
8 inlineHelpText=False,
9 blockHelpText=False,
10 disabled=False,
11 checked=False):
12 """
13 *Generate a radio - TBS style*
15 **Key Arguments**
17 - ``optionText`` -- the text associated with this checkbox
18 - ``optionNumber`` -- the order in the option list
19 - ``htmlId`` -- the html id of the element
20 - ``inlineHelpText`` -- inline and block level support for help text that appears around form controls
21 - ``blockHelpText`` -- a longer block of help text that breaks onto a new line and may extend beyond one line
22 - ``disabled`` -- add the disabled attribute on an input to prevent user input
23 - ``checked`` -- is the radio button checked by default
26 **Return**
28 - ``radio`` -- the radio
30 """
31 if inlineHelpText:
32 inlineHelpText = """<span class="help-inline">%(inlineHelpText)s</span>""" % locals(
33 )
34 else:
35 inlineHelpText = ""
37 if blockHelpText:
38 blockHelpText = """<span class="help-block">%(blockHelpText)s</span>""" % locals(
39 )
40 else:
41 blockHelpText = ""
43 if disabled:
44 disabled = """disabled"""
45 disabledId = "disabledId"
46 else:
47 disabled = ""
48 disabledId = ""
50 if checked is False:
51 checked = ""
52 else:
53 checked = "checked"
55 if not htmlId:
56 htmlId = ""
58 radio = """
59 <label class="radio">
60 <input type="radio" name="%(htmlId)s" id="%(htmlId)s %(disabledId)s %(htmlId)s" value="%(optionText)s" %(checked)s %(disabled)s>
61 %(optionText)s
62 </label>%(inlineHelpText)s%(inlineHelpText)s""" % locals()
64 return radio