]>
git.datanom.net - pwp.git/blob - app/models.py
1 from config
import ADMINS
2 from enum
import IntEnum
3 from baseorm
import BaseOrm
4 from flask_login
import mixins
18 __tablename__
= 'user'
27 self
.__oldValues
['name'] = self
.name
28 except AttributeError:
37 def email(self
, email
):
39 self
.__oldValues
['email'] = self
.email
40 except AttributeError:
46 return self
.__username
49 def username(self
, username
):
51 self
.__oldValues
['username'] = self
.username
52 except AttributeError:
54 self
.__username
= username
58 return self
.__password
61 def password(self
, password
):
63 self
.__oldValues
['password'] = self
.password
64 except AttributeError:
66 self
.__password
= password
68 def __init__(self
, name
, email
, username
, password
, id = -1):
73 self
.username
= username
74 self
.password
= password
76 def is_authenticated(self
):
82 def is_anonymous(self
):
89 return self
.email
in ADMINS
92 return '<User ID: %s Name: %s Email: %s username: %s>' % (self
.id, self
.name
, self
.email
, self
.username
)
94 class Portfolio(BaseOrm
):
95 __tablename__
= 'portfolio'
102 def name(self
, name
):
104 self
.__oldValues
['name'] = self
.name
105 except AttributeError:
114 def public(self
, public
):
116 self
.__oldValues
['public'] = self
.public
117 except AttributeError:
119 self
.__public
= public
123 return self
.__visible
126 def visible(self
, visible
):
128 self
.__oldValues
['visible'] = self
.visible
129 except AttributeError:
131 self
.__visible
= visible
138 def user(self
, user
):
140 self
.__oldValues
['user'] = self
.user
141 except AttributeError:
145 def __init__(self
, name
, user
, public
= False, visible
= False, id = -1):
150 self
.visible
= visible
151 app
.logger
.info("User: {0}".format(user
))
152 if (isinstance(user
, User
)):
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
))
160 def set_user_count(self
, usercount
):
161 self
.usercount
= usercount
164 return '<Portfolio ID: %s Name: %s Owner: %s>' % (self
.id, self
.name
, self
.user
)
166 class Album(BaseOrm
):
167 __tablename__
= 'album'
174 def name(self
, name
):
176 self
.__oldValues
['name'] = self
.name
177 except AttributeError:
186 def public(self
, public
):
188 self
.__oldValues
['public'] = self
.public
189 except AttributeError:
191 self
.__public
= public
195 return self
.__visible
198 def visible(self
, visible
):
200 self
.__oldValues
['visible'] = self
.visible
201 except AttributeError:
203 self
.__visible
= visible
207 return self
.__portfolio
210 def portfolio(self
, portfolio
):
212 self
.__oldValues
['portfolio'] = self
.portfolio
213 except AttributeError:
215 self
.__portfolio
= portfolio
217 def __init__(self
, name
, portfolio
):
223 if not isinstance(portfolio
, Portfolio
):
224 raise Exception("{0}: Not a 'Portfolio'".format(portfolio
))
225 self
.portfolio
= portfolio
227 def set_user_count(self
, usercount
):
228 self
.usercount
= usercount
231 return '<Album Name: %r Portfolio: %r>' % (self
.name
, self
.portfolio
)
233 class Photo(BaseOrm
):
234 __tablename__
= 'photo'
241 def name(self
, name
):
243 self
.__oldValues
['name'] = self
.name
244 except AttributeError:
253 def public(self
, public
):
255 self
.__oldValues
['public'] = self
.public
256 except AttributeError:
258 self
.__public
= public
262 return self
.__visible
265 def visible(self
, visible
):
267 self
.__oldValues
['visible'] = self
.visible
268 except AttributeError:
270 self
.__visible
= visible
277 def album(self
, album
):
279 self
.__oldValues
['album'] = self
.album
280 except AttributeError:
289 def file(self
, file):
291 self
.__oldValues
['file'] = self
.file
292 except AttributeError:
301 def exif(self
, exif
):
303 self
.__oldValues
['exif'] = self
.exif
304 except AttributeError:
313 def format(self
, format
):
315 self
.__oldValues
['format'] = self
.format
316 except AttributeError:
318 self
.__format
= format
320 def __init__(self
, name
, album
):
326 if not isinstance(album
, Album
):
327 raise Exception("{0}: Not a 'Album'".format(album
))
331 self
.format
= Format
.raw
.value
334 return '<Photo Name: %r File: %r Format: %r Album: %r>' % (self
.name
, self
.file, self
.format
, self
.album
)
336 class AccessRight(BaseOrm
):
337 __tablename__
= 'accessright'
344 def perm(self
, perm
):
346 self
.__oldValues
['perm'] = self
.perm
347 except AttributeError:
356 def user(self
, user
):
358 self
.__oldValues
['user'] = self
.user
359 except AttributeError:
363 def __init__(self
, user
):
366 self
.perm
= Role
.read
.value
367 if not isinstance(user
, User
):
368 raise Exception("{0}: Not a 'User'".format(user
))
372 return '<AccessRight Right: %r User: %r>' % (self
.perm
, self
.user
)
374 class MyAnonymous(mixins
.AnonymousUserMixin
):
376 name
= 'Anonymous User'
377 email
= 'no@email.com'
381 def is_authenticated(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.