Hide keyboard shortcuts

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 * 

4 

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* 

19 

20 **Key Arguments** 

21 

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 

29  

30 

31 **Return** 

32 

33 - ``inlineForm`` -- the inline form 

34  

35 """ 

36 falseList = [navBarPull, ] 

37 

38 for i in range(len(falseList)): 

39 if not falseList[i]: 

40 falseList[i] = "" 

41 

42 [navBarPull, ] = falseList 

43 

44 if span is False: 

45 span = "" 

46 else: 

47 span = "span%(span)s" % locals() 

48 

49 if offset is False: 

50 offset = "" 

51 else: 

52 offset = "offset%(offset)s" % locals() 

53 

54 if not htmlClass: 

55 htmlClass = "" 

56 

57 if postInBackground is True: 

58 postInBackground = "postInBackground" 

59 else: 

60 postInBackground = "" 

61 

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 = "" 

72 

73 if navBarPull: 

74 navBarPull = "pull-%(navBarPull)s" % locals() 

75 

76 thisList = ["inline", "horizontal", "search"] 

77 if formType in thisList: 

78 formType = """form-%(formType)s""" % locals() 

79 

80 htmlInput = "" 

81 if formType == "navbar-search": 

82 htmlInput = """%(htmlInput)s<input type="text" class="search-query" placeholder="search">""" % locals() 

83 

84 if htmlId: 

85 htmlId = """id="%(htmlId)s" """ % locals() 

86 else: 

87 htmlId = "" 

88 

89 if openInNewTab is not False: 

90 openInNewTab = """ target="_blank" """ 

91 

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 ) 

94 

95 return form