]> git.datanom.net - pwp.git/blame - app/models.py
initial commit
[pwp.git] / app / models.py
CommitLineData
e5424f29
MR
1from config import ADMINS
2from enum import IntEnum
3import DB
4#from flask_login import mixins
5
6class Format(IntEnum):
7 jpg = 1
8 raw = 2
9 tiff = 3
10
11class Role(IntEnum):
12 read = 1
13 write = 2
14 admin = 3
15
16class User(DB.baseorm.BaseOrm):
17 __tablename__ = 'user'
18
19 @property
20 def name(self):
21 return self.__name
22
23 @name.setter
24 def name(self, name):
25 self.__name = name
26 self.notify(self)
27
28 @property
29 def email(self):
30 return self.__email
31
32 @email.setter
33 def email(self, email):
34 self.__email = email
35 self.notify(self)
36
37 @property
38 def username(self):
39 return self.__username
40
41 @username.setter
42 def username(self, username):
43 self.__username = username
44 self.notify(self)
45
46 @property
47 def password(self):
48 return self.__password
49
50 @password.setter
51 def password(self, password):
52 self.__password = password
53 self.notify(self)
54
55 def __init__(self, name, email, username, password):
56 super().__init__()
57 self.email = email
58 self.id = -1
59 self.name = name
60 self.username = username
61 self.password = password
62
63 def is_authenticated(self):
64 return True
65
66 def is_active(self):
67 return True
68
69 def is_anonymous(self):
70 return False
71
72 def is_admin(self):
73 return self.email in ADMINS
74
75 def __repr__(self):
76 return '<User ID: %s Name: %s Email: %s username: %s>' % (self.id, self.name, self.email, self.username)
77
78class Portfolio(DB.baseorm.BaseOrm):
79 __tablename__ = 'portfolio'
80
81 @property
82 def name(self):
83 return self.__name
84
85 @name.setter
86 def name(self, name):
87 self.__name = name
88
89 @property
90 def public(self):
91 return self.__public
92
93 @public.setter
94 def public(self, public):
95 self.__public = public
96
97 @property
98 def visible(self):
99 return self.__visible
100
101 @visible.setter
102 def visible(self, visible):
103 self.__visible = visible
104
105 @property
106 def user(self):
107 return self.__user
108
109 @user.setter
110 def user(self, user):
111 self.__user = user
112
113 def __init__(self, name, user):
114 super().__init__()
115 self.id = -1
116 self.name = name
117 self.public = False
118 self.visible = False
119 if not isinstance(user, User):
120 raise Exception("{0}: Not a 'User'".format(user))
121 self.user = user
122
123 def set_user_count(self, usercount):
124 self.usercount = usercount
125
126 def __repr__(self):
127 return '<Portfolio Name: %s Owner: %s>' % (self.name, self.user)
128
129class Album(DB.baseorm.BaseOrm):
130 __tablename__ = 'album'
131
132 @property
133 def name(self):
134 return self.__name
135
136 @name.setter
137 def name(self, name):
138 self.__name = name
139
140 @property
141 def public(self):
142 return self.__public
143
144 @public.setter
145 def public(self, public):
146 self.__public = public
147
148 @property
149 def visible(self):
150 return self.__visible
151
152 @visible.setter
153 def visible(self, visible):
154 self.__visible = visible
155
156 @property
157 def portfolio(self):
158 return self.__portfolio
159
160 @portfolio.setter
161 def portfolio(self, portfolio):
162 self.__portfolio = portfolio
163
164 def __init__(self, name, portfolio):
165 super().__init__()
166 self.id = -1
167 self.name = name
168 self.public = False
169 self.visible = False
170 if not isinstance(portfolio, Portfolio):
171 raise Exception("{0}: Not a 'Portfolio'".format(portfolio))
172 self.portfolio = portfolio
173
174 def set_user_count(self, usercount):
175 self.usercount = usercount
176
177 def __repr__(self):
178 return '<Album Name: %r Portfolio: %r>' % (self.name, self.portfolio)
179
180class Photo(DB.baseorm.BaseOrm):
181 __tablename__ = 'photo'
182
183 @property
184 def name(self):
185 return self.__name
186
187 @name.setter
188 def name(self, name):
189 self.__name = name
190
191 @property
192 def public(self):
193 return self.__public
194
195 @public.setter
196 def public(self, public):
197 self.__public = public
198
199 @property
200 def visible(self):
201 return self.__visible
202
203 @visible.setter
204 def visible(self, visible):
205 self.__visible = visible
206
207 @property
208 def album(self):
209 return self.__album
210
211 @album.setter
212 def album(self, album):
213 self.__album = album
214
215 @property
216 def file(self):
217 return self.__file
218
219 @file.setter
220 def file(self, file):
221 self.__file = file
222
223 @property
224 def exif(self):
225 return self.__exif
226
227 @exif.setter
228 def exif(self, exif):
229 self.__exif = exif
230
231 @property
232 def format(self):
233 return self.__format
234
235 @format.setter
236 def format(self, format):
237 self.__format = format
238
239 def __init__(self, name, album):
240 super().__init__()
241 self.id = -1
242 self.name = name
243 self.public = False
244 self.visible = False
245 if not isinstance(album, Album):
246 raise Exception("{0}: Not a 'Album'".format(album))
247 self.album = album
248 self.file = None
249 self.exif = None
250 self.format = Format.raw.value
251
252 def __repr__(self):
253 return '<Photo Name: %r File: %r Format: %r Album: %r>' % (self.name, self.file, self.format, self.album)
254
255class AccessRight(DB.baseorm.BaseOrm):
256 __tablename__ = 'accessright'
257
258 @property
259 def perm(self):
260 return self.__perm
261
262 @perm.setter
263 def perm(self, perm):
264 self.__perm = perm
265
266 @property
267 def user(self):
268 return self.__user
269
270 @user.setter
271 def user(self, user):
272 self.__user = user
273
274 def __init__(self, user):
275 super().__init__()
276 self.id = -1
277 self.perm = Role.read.value
278 if not isinstance(user, User):
279 raise Exception("{0}: Not a 'User'".format(user))
280 self.user = user
281
282 def __repr__(self):
283 return '<AccessRight Right: %r User: %r>' % (self.perm, self.user)
284
285#class MyAnonymous(mixins.AnonymousUserMixin):
286# id = -1
287# name = 'Anonymous User'
288# email = 'no@email.com'
289# username = 'None'
290#
291# @property
292# def is_authenticated(self):
293# return False
294#
295# @property
296# def is_admin(self):
297# return False
298#
299# def get_id(self):
300# return self.id
301#
302# def __repr__(self):
303# return '<User Name: %r Email: %r username: %r>' % (self.name, self.email, self.username)
This page took 0.182168 seconds and 5 git commands to generate.