]> git.datanom.net - wpp.git/blame - app/models.py
rm test access
[wpp.git] / app / models.py
CommitLineData
047d4d29
MR
1from app import db
2from config import ADMINS
3import enum
4
5class Format(enum.Enum):
6 jpg = 1
7 raw = 2
8 tiff = 3
9
10class Role(enum.Enum):
11 read = 1
12 write = 2
13 admin = 3
14
15class User(db.Model):
16 __tablename__ = 'user'
17 id = db.Column(db.Integer, primary_key=True, autoincrement=True)
18 name = db.Column(db.String(255))
19 email = db.Column(db.String(255), index=True, unique=True)
20 username = db.Column(db.String(255), index=True, unique=True)
21 password = db.Column(db.String(255))
22 portfolios = db.relationship('Portfolio', backref='owner', lazy=True, cascade='save-update, merge, delete, delete-orphan')
23 acl = db.relationship('AccessRight', backref='user', lazy=True)
24
25 @property
26 def is_authenticated(self):
27 return True
28
29 @property
30 def is_active(self):
31 return True
32
33 @property
34 def is_anonymous(self):
35 return False
36
37 @property
38 def is_admin(self):
39 return self.email in ADMINS
40
41 def get_id(self):
42 return str(self.id) # python 3
43
44 def __repr__(self):
45 return '<User Name: %r Email: %r username: %r>' % (self.name, self.email, self.username)
46
47class Portfolio(db.Model):
48 __tablename__ = 'portfolio'
49 id = db.Column(db.Integer, primary_key=True, autoincrement=True)
50 name = db.Column(db.String(255))
51 user_id = db.Column(db.ForeignKey('user.id', onupdate='CASCADE', ondelete='CASCADE'), nullable=False)
52 albums = db.relationship('Album', backref='portfolio', lazy=True, cascade='save-update, merge, delete, delete-orphan')
53
54 def __repr__(self):
55 return '<Portfolio Name: %r Owner: %r>' % (self.name, self.owner)
56
57class Album(db.Model):
58 __tablename__ = 'album'
59 id = db.Column(db.Integer, primary_key=True, autoincrement=True)
60 name = db.Column(db.String(255))
61 photos = db.relationship('Photo', backref='album', lazy=True, cascade='save-update, merge, delete, delete-orphan')
62 portfolio_id = db.Column(db.ForeignKey('portfolio.id', onupdate='CASCADE', ondelete='CASCADE'), nullable=False)
63
64 def __repr__(self):
65 return '<Album Name: %r Portfolio: %r>' % (self.name, self.portfolio)
66
67class Photo(db.Model):
68 __tablename__ = 'photo'
69 id = db.Column(db.Integer, primary_key=True, autoincrement=True)
70 file = db.Column(db.String(255))
71 name = db.Column(db.String(255))
72 exif = db.Column(db.Text)
73 format = db.Column(db.Enum(Format))
74 sibling = db.Column(db.ForeignKey('photo.id'))
75 album_id = db.Column(db.ForeignKey('album.id', onupdate='CASCADE', ondelete='CASCADE'), nullable=False)
76
77 def __repr__(self):
78 return '<Photo Name: %r File: %r Format: %r Album: %r>' % (self.name, self.file, self.format, self.album)
79
80class AccessRight(db.Model):
81 __tablename__ = 'accessright'
82 id = db.Column(db.Integer, primary_key = True, autoincrement=True)
83 right = db.Column(db.Enum(Role))
84 user_id = db.Column(db.ForeignKey('user.id', onupdate='CASCADE', ondelete='CASCADE'), nullable=False)
85 object = db.Column(db.Integer)
86
87 def __repr__(self):
88 return '<AccessRight Right: %r User: %r Object: %r>' % (self.right, self.user, self.object)
This page took 0.059433 seconds and 6 git commands to generate.