summaryrefslogtreecommitdiff
path: root/stashbox/stashbox.py
diff options
context:
space:
mode:
Diffstat (limited to 'stashbox/stashbox.py')
-rw-r--r--stashbox/stashbox.py96
1 files changed, 96 insertions, 0 deletions
diff --git a/stashbox/stashbox.py b/stashbox/stashbox.py
new file mode 100644
index 0000000..ba2188d
--- /dev/null
+++ b/stashbox/stashbox.py
@@ -0,0 +1,96 @@
+""" Basic todo list using webpy 0.3 """
+import web
+import models
+
+### Url mappings
+
+urls = (
+ '/', 'Index',
+ '/admin/users/', 'UsersAdmin',
+ '/del/(\d+)', 'Delete'
+)
+
+### Templates
+render = web.template.render('templates', base='base')
+
+class Index:
+
+ result = models.get_users()
+ users = []
+
+ for user in result:
+ users.append((user.id, user.username))
+
+ form = web.form.Form(
+ web.form.Textbox('name', web.form.notnull, description="Name:"),
+ web.form.Dropdown('owner_id', users, description="Owner:"),
+ web.form.Dropdown('users',
+ users,
+ description="Users:",
+ **{'multiple': 'multiple', 'size': 5}
+ ),
+ web.form.Textbox('new_name', description="New user:"),
+ web.form.Password('new_password', description="New user password:"),
+ web.form.Button('Add stash'),
+ )
+
+ def GET(self):
+ """ Show page """
+ folders = models.get_folders()
+
+ return render.index(folders, self.form)
+
+ def POST(self):
+ """ Add new entry """
+ form = self.form()
+ if not form.validates():
+ folders = models.get_folders()
+ return render.index(folders, form)
+
+ folder_id = models.new_folder(form.d.name, form.d.owner_id)
+
+ for user_id in form.d.users:
+ models.authorize_user(user_id, folder_id)
+
+ if form.d.new_name:
+ new_user_id = models.add_user(form.d.new_name, form.d.new_password)
+ models.authorize_user(new_user_id, folder_id)
+
+ scoob
+
+ raise web.seeother('/')
+
+class Delete:
+
+ def POST(self, id):
+ """ Delete based on ID """
+ id = int(id)
+ models.del_folder(id)
+ raise web.seeother('/')
+
+class UsersAdmin:
+ form = web.form.Form(
+ web.form.Textbox('username', web.form.notnull, description="Username:"),
+ web.form.Password('password', web.form.notnull, description="Password:"),
+ web.form.Button('Add user'),
+ )
+
+ def GET(self):
+ """ Show page """
+ users = models.get_users()
+ form = self.form()
+ return render.usersadmin(users, form)
+
+ def POST(self):
+ """ Add new entry """
+ form = self.form()
+ if not form.validates():
+ users = models.get_users()
+ return render.index(users, form)
+ models.add_user(form.d.username, form.d.password)
+ raise web.seeother('/admin/users/')
+
+app = web.application(urls, globals())
+
+if __name__ == '__main__':
+ app.run()