Coverage for khufu/forms/checkbox.py : 74%

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 checkbox(
5 optionText="",
6 inline=False,
7 optionNumber=1,
8 htmlId=False,
9 inlineHelpText=False,
10 blockHelpText=False,
11 disabled=False,
12 checked=False):
13 """
14 *Generate a checkbox - TBS style*
16 **Key Arguments**
18 - ``optionText`` -- the text associated with this checkbox
19 - ``inline`` -- display the checkboxes inline?
20 - ``optionNumber`` -- option number of inline
21 - ``htmlId`` -- htmlId
22 - ``inlineHelpText`` -- inline and block level support for help text that appears around form controls
23 - ``blockHelpText`` -- a longer block of help text that breaks onto a new line and may extend beyond one line
24 - ``disabled`` -- add the disabled attribute on an input to prevent user input
25 - ``checked`` -- the default checked/unchecked state of the box
28 **Return**
30 - ``checkbox`` -- the checkbox
32 """
33 if inline is True:
34 inline = "inline"
35 optionNumber = "option%(optionNumber)s" % locals()
36 else:
37 inline = ""
38 optionNumber = ""
40 if inlineHelpText:
41 inlineHelpText = """<span class="help-inline">%(inlineHelpText)s</span>""" % locals(
42 )
43 else:
44 inlineHelpText = ""
46 if blockHelpText:
47 blockHelpText = """<span class="help-block">%(blockHelpText)s</span>""" % locals(
48 )
49 else:
50 blockHelpText = ""
52 if disabled:
53 disabled = """disabled"""
54 disabledId = "disabledId"
55 else:
56 disabled = ""
57 disabledId = ""
59 if not htmlId:
60 htmlId = ""
61 name = ""
62 else:
63 name = """name="%(htmlId)s" """ % locals()
65 if not checked:
66 checked = ""
67 else:
68 checked = "checked"
70 checkbox = """
71 <label class="checkbox %(inline)s">
72 <input type="checkbox" %(name)s value="%(optionNumber)s" id="%(htmlId)s %(disabledId)s" %(disabled)s %(checked)s>
73 %(optionText)s
74 </label>%(inlineHelpText)s%(blockHelpText)s""" % locals()
76 return checkbox