functional framework in place

This commit is contained in:
Andrew Davidson 2012-02-27 22:12:05 -08:00
parent 0e5ce9ac8c
commit a577e52f1a
4 changed files with 79 additions and 23 deletions

View file

@ -1,26 +1,70 @@
import web import web
from web import form
db = web.database(dbn='mysql', user='mysecrets', pw='horsebatteries', db = web.database(dbn='mysql', user='mysecrets', pw='horsebatteries',
db='mysecrets') db='mysecrets')
urls = ( urls = (
'/secret/', 'index', '/secret/api/(.*)', 'api',
'/secret/api/(.*)', 'api' '/secret/(.*)', 'index'
) )
app = web.application(urls, globals()) app = web.application(urls, globals())
class index: render = web.template.render('templates/')
def GET(self):
return '''\ create = form.Form(
<html> form.Textbox('base_url', description="domain"),
<head> form.Textbox('username'),
<title>mySecrets</title> form.Password('password'),
</head> )
<body>
These are mySecrets. There is nothing for you here.
</body> class index:
</html>''' def GET(self, method):
if method == 'get':
if web.input():
i = web.input()
selected = db.select('passwords', where='`base_url`="'+i.base_url+'"')
if len(selected) > 0:
pairs = '<ul>'
for p in selected:
pairs += '<li>'+p.username+', '+p.password+'</li>'
pairs += '</ul>'
else:
pairs = "<p>Sorry buddy, you're outta luck</p>"
body = '<h1>'+i.base_url+'</h1>\n'+pairs
return render.page(i.base_url, body)
else:
return render.page('get','<p>need input.</p>')
if method == 'new':
f = create()
body = '<h1>Create</h1>\n<form class="form" method="get" \
action="/secret/create">\n'+\
f.render()+ '\n<input type="submit" name="submit" id="submit"/></form>'
return render.page('create',body)
if method == 'create':
i = web.input()
n = db.insert('passwords', username=i.username, password=i.password, \
base_url=i.base_url)
body = '<h1>'+i.base_url+'</h1><p>'+i.username+', '+i.password+'</p>'
return render.page('Created', body)
else:
return render.page('mySecrets', '<p>These are mySecrets. There is nothing for you here.</p>')
class api: class api:
def GET(self, method): def GET(self, method):
@ -38,7 +82,7 @@ class api:
tmp = '' tmp = ''
for pair in pairs: for pair in pairs:
tmp += pair.username+','+pair.password+'\n' tmp += pair.username+','+pair.password+'\n'
return tmp return tmp
@ -46,14 +90,14 @@ class api:
return 'mySecrets API ' + method return 'mySecrets API ' + method
def POST(self, method): def POST(self, method):
if method == "create": i = web.input()
i = web.input() n = db.insert('passwords', username=i.username, password=i.password, \
n = db.insert('passwords', username=i.username, password=i.password, \ base_url=i.base_url)
base_url=i.base_url)
return 'Created.' body = '<h1>'+i.base_url+'</h1><p>'+i.username+', '+i.password+'</p>'
else:
return 'No method.' return render.page('Created', body)
if __name__ == "__main__": if __name__ == "__main__":
app.run() app.run()

1
static/create.js Normal file
View file

@ -0,0 +1 @@
// create.js

1
static/get.js Normal file
View file

@ -0,0 +1 @@
// get.js

10
templates/page.html Normal file
View file

@ -0,0 +1,10 @@
$def with (title, body)
<html>
<head>
<title>$title</title>
</head>
<body>
$:body
</body>
</html>