]> git.datanom.net - pwp.git/blob - app/models.py
Half way through migration away from sqlalchemy
[pwp.git] / app / models.py
1 from config import ADMINS
2 from enum import IntEnum
3 from baseorm import BaseOrm
4 from flask_login import mixins
5 from app import app
6
7 class Format(IntEnum):
8 jpg = 1
9 raw = 2
10 tiff = 3
11
12 class Role(IntEnum):
13 read = 1
14 write = 2
15 admin = 3
16
17 class User(BaseOrm):
18 __tablename__ = 'user'
19
20 @property
21 def name(self):
22 return self.__name
23
24 @name.setter
25 def name(self, name):
26 try:
27 self.__oldValues['name'] = self.name
28 except AttributeError:
29 pass
30 self.__name = name
31
32 @property
33 def email(self):
34 return self.__email
35
36 @email.setter
37 def email(self, email):
38 try:
39 self.__oldValues['email'] = self.email
40 except AttributeError:
41 pass
42 self.__email = email
43
44 @property
45 def username(self):
46 return self.__username
47
48 @username.setter
49 def username(self, username):
50 try:
51 self.__oldValues['username'] = self.username
52 except AttributeError:
53 pass
54 self.__username = username
55
56 @property
57 def password(self):
58 return self.__password
59
60 @password.setter
61 def password(self, password):
62 try:
63 self.__oldValues['password'] = self.password
64 except AttributeError:
65 pass
66 self.__password = password
67
68 def __init__(self, name, email, username, password, id = -1):
69 super().__init__()
70 self.email = email
71 self.id = id
72 self.name = name
73 self.username = username
74 self.password = password
75
76 def is_authenticated(self):
77 return True
78
79 def is_active(self):
80 return True
81
82 def is_anonymous(self):
83 return False
84
85 def get_id(self):
86 return self.id
87
88 def is_admin(self):
89 return self.email in ADMINS
90
91 def __repr__(self):
92 return '<User ID: %s Name: %s Email: %s username: %s>' % (self.id, self.name, self.email, self.username)
93
94 class Portfolio(BaseOrm):
95 __tablename__ = 'portfolio'
96
97 @property
98 def name(self):
99 return self.__name
100
101 @name.setter
102 def name(self, name):
103 try:
104 self.__oldValues['name'] = self.name
105 except AttributeError:
106 pass
107 self.__name = name
108
109 @property
110 def public(self):
111 return self.__public
112
113 @public.setter
114 def public(self, public):
115 try:
116 self.__oldValues['public'] = self.public
117 except AttributeError:
118 pass
119 self.__public = public
120
121 @property
122 def visible(self):
123 return self.__visible
124
125 @visible.setter
126 def visible(self, visible):
127 try:
128 self.__oldValues['visible'] = self.visible
129 except AttributeError:
130 pass
131 self.__visible = visible
132
133 @property
134 def user(self):
135 return self.__user
136
137 @user.setter
138 def user(self, user):
139 try:
140 self.__oldValues['user'] = self.user
141 except AttributeError:
142 pass
143 self.__user = user
144
145 def __init__(self, name, user, public = False, visible = False, id = -1):
146 super().__init__()
147 self.id = id
148 self.name = name
149 self.public = public
150 self.visible = visible
151 app.logger.info("User: {0}".format(user))
152 if (isinstance(user, User)):
153 u = user
154 else:
155 u = User(user[1], user[2], user[3], user[4], user[0])
156 if not isinstance(u, User):
157 raise Exception("{0}: Not a 'User'".format(user))
158 self.user = u
159
160 def set_user_count(self, usercount):
161 self.usercount = usercount
162
163 def __repr__(self):
164 return '<Portfolio ID: %s Name: %s Owner: %s>' % (self.id, self.name, self.user)
165
166 class Album(BaseOrm):
167 __tablename__ = 'album'
168
169 @property
170 def name(self):
171 return self.__name
172
173 @name.setter
174 def name(self, name):
175 try:
176 self.__oldValues['name'] = self.name
177 except AttributeError:
178 pass
179 self.__name = name
180
181 @property
182 def public(self):
183 return self.__public
184
185 @public.setter
186 def public(self, public):
187 try:
188 self.__oldValues['public'] = self.public
189 except AttributeError:
190 pass
191 self.__public = public
192
193 @property
194 def visible(self):
195 return self.__visible
196
197 @visible.setter
198 def visible(self, visible):
199 try:
200 self.__oldValues['visible'] = self.visible
201 except AttributeError:
202 pass
203 self.__visible = visible
204
205 @property
206 def portfolio(self):
207 return self.__portfolio
208
209 @portfolio.setter
210 def portfolio(self, portfolio):
211 try:
212 self.__oldValues['portfolio'] = self.portfolio
213 except AttributeError:
214 pass
215 self.__portfolio = portfolio
216
217 def __init__(self, name, portfolio):
218 super().__init__()
219 self.id = -1
220 self.name = name
221 self.public = False
222 self.visible = False
223 if not isinstance(portfolio, Portfolio):
224 raise Exception("{0}: Not a 'Portfolio'".format(portfolio))
225 self.portfolio = portfolio
226
227 def set_user_count(self, usercount):
228 self.usercount = usercount
229
230 def __repr__(self):
231 return '<Album Name: %r Portfolio: %r>' % (self.name, self.portfolio)
232
233 class Photo(BaseOrm):
234 __tablename__ = 'photo'
235
236 @property
237 def name(self):
238 return self.__name
239
240 @name.setter
241 def name(self, name):
242 try:
243 self.__oldValues['name'] = self.name
244 except AttributeError:
245 pass
246 self.__name = name
247
248 @property
249 def public(self):
250 return self.__public
251
252 @public.setter
253 def public(self, public):
254 try:
255 self.__oldValues['public'] = self.public
256 except AttributeError:
257 pass
258 self.__public = public
259
260 @property
261 def visible(self):
262 return self.__visible
263
264 @visible.setter
265 def visible(self, visible):
266 try:
267 self.__oldValues['visible'] = self.visible
268 except AttributeError:
269 pass
270 self.__visible = visible
271
272 @property
273 def album(self):
274 return self.__album
275
276 @album.setter
277 def album(self, album):
278 try:
279 self.__oldValues['album'] = self.album
280 except AttributeError:
281 pass
282 self.__album = album
283
284 @property
285 def file(self):
286 return self.__file
287
288 @file.setter
289 def file(self, file):
290 try:
291 self.__oldValues['file'] = self.file
292 except AttributeError:
293 pass
294 self.__file = file
295
296 @property
297 def exif(self):
298 return self.__exif
299
300 @exif.setter
301 def exif(self, exif):
302 try:
303 self.__oldValues['exif'] = self.exif
304 except AttributeError:
305 pass
306 self.__exif = exif
307
308 @property
309 def format(self):
310 return self.__format
311
312 @format.setter
313 def format(self, format):
314 try:
315 self.__oldValues['format'] = self.format
316 except AttributeError:
317 pass
318 self.__format = format
319
320 def __init__(self, name, album):
321 super().__init__()
322 self.id = -1
323 self.name = name
324 self.public = False
325 self.visible = False
326 if not isinstance(album, Album):
327 raise Exception("{0}: Not a 'Album'".format(album))
328 self.album = album
329 self.file = None
330 self.exif = None
331 self.format = Format.raw.value
332
333 def __repr__(self):
334 return '<Photo Name: %r File: %r Format: %r Album: %r>' % (self.name, self.file, self.format, self.album)
335
336 class AccessRight(BaseOrm):
337 __tablename__ = 'accessright'
338
339 @property
340 def perm(self):
341 return self.__perm
342
343 @perm.setter
344 def perm(self, perm):
345 try:
346 self.__oldValues['perm'] = self.perm
347 except AttributeError:
348 pass
349 self.__perm = perm
350
351 @property
352 def user(self):
353 return self.__user
354
355 @user.setter
356 def user(self, user):
357 try:
358 self.__oldValues['user'] = self.user
359 except AttributeError:
360 pass
361 self.__user = user
362
363 def __init__(self, user):
364 super().__init__()
365 self.id = -1
366 self.perm = Role.read.value
367 if not isinstance(user, User):
368 raise Exception("{0}: Not a 'User'".format(user))
369 self.user = user
370
371 def __repr__(self):
372 return '<AccessRight Right: %r User: %r>' % (self.perm, self.user)
373
374 class MyAnonymous(mixins.AnonymousUserMixin):
375 id = -1
376 name = 'Anonymous User'
377 email = 'no@email.com'
378 username = 'None'
379
380 @property
381 def is_authenticated(self):
382 return False
383
384 @property
385 def is_admin(self):
386 return False
387
388 def get_id(self):
389 return self.id
390
391 def __repr__(self):
392 return '<User Name: %r Email: %r username: %r>' % (self.name, self.email, self.username)
This page took 0.190159 seconds and 6 git commands to generate.