-
Notifications
You must be signed in to change notification settings - Fork 1
/
models.py
67 lines (50 loc) · 1.92 KB
/
models.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
64
65
66
67
from sqlalchemy import Table, Column, Integer, String, Binary, Boolean
from sqlalchemy.orm import mapper
from database import metadata, db_session
class Upload():
query = db_session.query_property()
def __init__(self, hash, short_url, mime_type):
self.hash = hash
self.short_url = short_url
self.mime_type = mime_type
def __repr__(self):
return '<Upload %r>' % (self.hash)
class User():
query = db_session.query_property()
def __init__(self, username, password, salt):
self.username = username
self.password = password
self.salt = salt
def __repr__(self):
return '<User %r>' % (self.username)
class Invite():
query = db_session.query_property()
def __init__(self, code, creator_id):
self.code = code
self.creator_id = creator_id
def __repr__(self):
return '<Invite %r>' % (self.code)
uploads = Table('uploads', metadata,
Column('id', Integer, primary_key=True),
Column('hash', Binary(20), unique=True),
Column('short_url', String(7), unique=True),
Column('mime_type', String(255)),
Column('blocked', Boolean, default=False),
)
users = Table('users', metadata,
Column('id', Integer, primary_key=True),
Column('username', String(255), unique=True),
Column('password', Binary(64)),
Column('salt', String(42)),
Column('token', String(32)),
Column('is_admin', Boolean, default=False),
)
invites = Table('invites', metadata,
Column('id', Integer, primary_key=True),
Column('code', String(32), unique=True),
Column('creator_id', Integer),
Column('redeemed', Boolean, default=False),
)
mapper(Upload, uploads)
mapper(User, users)
mapper(Invite, invites)