-
Notifications
You must be signed in to change notification settings - Fork 1
/
models.py
52 lines (39 loc) · 1.51 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
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, thumbnail_url, public):
self.hash = hash
self.short_url = short_url
self.mime_type = mime_type
self.thumbnail_url = thumbnail_url
self.public = public
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)
uploads = Table('uploads', metadata,
Column('id', Integer, primary_key=True),
Column('hash', Binary(20), unique=True),
Column('short_url', String(7), unique=True),
Column('thumbnail_url', String(255)),
Column('mime_type', String(255)),
Column('blocked', Boolean, default=False),
Column('public', Boolean, default=True),
)
users = Table('users', metadata,
Column('id', Integer, primary_key=True),
Column('username', String(255)),
Column('password', Binary(64)),
Column('salt', String(42)),
Column('token', String(32)),
)
mapper(Upload, uploads)
mapper(User, users)