comparison plugins/cherrypy/lib/defaultformmask.py @ 0:4385a7d0efd1 grumpy-goblin

Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
author sirebral
date Tue, 14 Jul 2009 16:41:58 -0500
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4385a7d0efd1
1 """
2 Copyright (c) 2004, CherryPy Team (team@cherrypy.org)
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without modification,
6 are permitted provided that the following conditions are met:
7
8 * Redistributions of source code must retain the above copyright notice,
9 this list of conditions and the following disclaimer.
10 * Redistributions in binary form must reproduce the above copyright notice,
11 this list of conditions and the following disclaimer in the documentation
12 and/or other materials provided with the distribution.
13 * Neither the name of the CherryPy Team nor the names of its contributors
14 may be used to endorse or promote products derived from this software
15 without specific prior written permission.
16
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
21 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 """
28
29 """
30 Default mask for the form.py module
31 """
32
33 def defaultMask(field):
34 res="<tr><td valign=top>%s</td>"%field.label
35 if field.typ=='text':
36 res+='<td><input name="%s" type=text value="%s" size=%s></td>'%(field.name, field.currentValue, field.size)
37 elif field.typ=='forced':
38 res+='<td><input name="%s" type=hidden value="%s">%s</td>'%(field.name, field.currentValue, field.currentValue)
39 elif field.typ=='password':
40 res+='<td><input name="%s" type=password value="%s"></td>'%(field.name, field.currentValue)
41 elif field.typ=='select':
42 res+='<td><select name="%s">'%field.name
43 for option in field.optionList:
44 if type(option)==type(()):
45 optionId, optionLabel=option
46 if optionId==field.currentValue or str(optionId)==field.currentValue: res+="<option selected value=%s>%s</option>"%(optionId, optionLabel)
47 else: res+="<option value=%s>%s</option>"%(optionId, optionLabel)
48 else:
49 if option==field.currentValue: res+="<option selected>%s</option>"%option
50 else: res+="<option>%s</option>"%option
51 res+='</select></td>'
52 elif field.typ=='textarea':
53 # Size is colsxrows
54 if field.size==15: size="15x15"
55 else: size=field.size
56 cols, rows=size.split('x')
57 res+='<td><textarea name="%s" rows="%s" cols="%s">%s</textarea></td>'%(field.name, rows, cols, field.currentValue)
58 elif field.typ=='submit':
59 res+='<td><input type=submit value="%s"></td>'%field.name
60 elif field.typ=='hidden':
61 if type(field.currentValue)==type([]): currentValue=field.currentValue
62 else: currentValue=[field.currentValue]
63 res=""
64 for value in currentValue:
65 res+='<input name="%s" type=hidden value="%s">'%(field.name, value)
66 return res
67 elif field.typ=='checkbox' or field.typ=='radio':
68 res+='<td>'
69 # print "##### currentValue:", field.currentValue # TBC
70 for option in field.optionList:
71 if type(option)==type(()): optionValue, optionLabel=option
72 else: optionValue, optionLabel=option, option
73 res+='<input type="%s" name="%s" value="%s"'%(field.typ, field.name, optionValue)
74 if type(field.currentValue)==type([]):
75 if optionValue in field.currentValue: res+=' checked'
76 else:
77 if optionValue==field.currentValue: res+=' checked'
78 res+='>&nbsp;&nbsp;%s<br />'%optionLabel
79 res+='</td>'
80 if field.errorMessage:
81 res+="<td><font color=red>%s</font></td>"%field.errorMessage
82 else:
83 res+="<td>&nbsp;</td>"
84 return res+"</tr>"
85 def hiddenMask(field):
86 if type(field.currentValue)==type([]): currentValue=field.currentValue
87 else: currentValue=[field.currentValue]
88 res=""
89 for value in currentValue:
90 res+='<input name="%s" type=hidden value="%s">'%(field.name, value)
91 return res
92 def defaultHeader(label):
93 return "<table>"
94 def defaultFooter(label):
95 return "</table>"
96 def echoMask(label):
97 return label