summaryrefslogtreecommitdiff
path: root/stashbox/stashbox.py
blob: ba2188d45e7550b89b275929feb7a660ba1871df (plain)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
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()