Coverage for khufu/forms/form.py : 84%

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 builtins import range
3from . import *
5def form(
6 content="",
7 formType="inline",
8 postToScript="",
9 htmlId=False,
10 htmlClass=False,
11 navBarPull=False,
12 postInBackground=False,
13 redirectUrl=False,
14 span=False,
15 offset=False,
16 openInNewTab=False):
17 """
18 *Generate a form - TBS style*
20 **Key Arguments**
22 - ``content`` -- the content
23 - ``formType`` -- the type if the form required [ "inline" | "horizontal" | "search" | "navbar-form" | "navbar-search" ]
24 - ``postToScript`` -- the script to post the form values to
25 - ``htmlId`` -- the id for the form
26 - ``navBarPull`` -- align the form is in a navBar [ false | right | left ]
27 - ``postInBackground`` -- submit form in background without refreshing page
28 - ``redirectUrl`` -- url to redirect to after form is submitted
31 **Return**
33 - ``inlineForm`` -- the inline form
35 """
36 falseList = [navBarPull, ]
38 for i in range(len(falseList)):
39 if not falseList[i]:
40 falseList[i] = ""
42 [navBarPull, ] = falseList
44 if span is False:
45 span = ""
46 else:
47 span = "span%(span)s" % locals()
49 if offset is False:
50 offset = ""
51 else:
52 offset = "offset%(offset)s" % locals()
54 if not htmlClass:
55 htmlClass = ""
57 if postInBackground is True:
58 postInBackground = "postInBackground"
59 else:
60 postInBackground = ""
62 if redirectUrl is not False:
63 redirectUrl = formInput(
64 # [ text | password | datetime | datetime-local | date | month | time | week | number | email | url | search | tel | color ]
65 ttype='text',
66 htmlId="redirectURL",
67 defaultValue=redirectUrl,
68 hidden=True
69 )
70 else:
71 redirectUrl = ""
73 if navBarPull:
74 navBarPull = "pull-%(navBarPull)s" % locals()
76 thisList = ["inline", "horizontal", "search"]
77 if formType in thisList:
78 formType = """form-%(formType)s""" % locals()
80 htmlInput = ""
81 if formType == "navbar-search":
82 htmlInput = """%(htmlInput)s<input type="text" class="search-query" placeholder="search">""" % locals()
84 if htmlId:
85 htmlId = """id="%(htmlId)s" """ % locals()
86 else:
87 htmlId = ""
89 if openInNewTab is not False:
90 openInNewTab = """ target="_blank" """
92 form = """<form class="%(formType)s %(navBarPull)s %(postInBackground)s %(span)s %(offset)s %(htmlClass)s" %(htmlId)s action="%(postToScript)s" method="post" %(openInNewTab)s>%(content)s%(htmlInput)s%(redirectUrl)s</form>""" % locals(
93 )
95 return form