-
Notifications
You must be signed in to change notification settings - Fork 0
/
formtest.py
executable file
·64 lines (47 loc) · 1.72 KB
/
formtest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
## The most Basic of modules you should always import ##
import sys, os, time, re, random, string, StringIO, subprocess
## We need to send mail ##
import smtplib
from email.mime.text import MIMEText
## Setup environment.... look in ./py_libs first ##
fqself = os.path.abspath(__file__)
my_libs = os.path.dirname(fqself) + '/py_libs/'
sys.path.insert(1, my_libs)
## Import dependencies ##
import web
import paramiko
import crypt, getpass, pwd
import xml.sax.saxutils
## Webpy Debug mode ##
web.config.debug = True
from web import form
render = web.template.render('/var/www/webpy-app/templates/')
urls = ('/', 'index')
app = web.application(urls, globals())
myform = form.Form(
form.Textbox("boe"),
form.Textbox("bax",
form.notnull,
form.regexp('\d+', 'Must be a digit'),
form.Validator('Must be more than 5', lambda x:int(x)>5)),
form.Textarea('moe'),
form.Checkbox('curly'),
form.Dropdown('french', ['mustard', 'fries', 'wine']))
class index:
def GET(self):
form = myform()
# make sure you create a copy of the form by calling it (line above)
# Otherwise changes will appear globally
return render.formtest(form)
def POST(self):
form = myform()
if not form.validates():
return render.formtest(form)
else:
# form.d.boe and form['boe'].value are equivalent ways of
# extracting the validated arguments from the form.
return "Grrreat success! boe: %s, bax: %s, Drop: %s" % (form.d.boe, form['bax'].value, form['french'].value)
####if __name__=="__main__":
#### web.internalerror = web.debugerror
#### app.run()
application = web.application(urls, globals()).wsgifunc()