from config import ADMINS
from enum import IntEnum
-import DB
-#from flask_login import mixins
+from baseorm import BaseOrm
+from flask_login import mixins
+from app import app
class Format(IntEnum):
jpg = 1
write = 2
admin = 3
-class User(DB.baseorm.BaseOrm):
+class User(BaseOrm):
__tablename__ = 'user'
@property
@name.setter
def name(self, name):
+ try:
+ self.__oldValues['name'] = self.name
+ except AttributeError:
+ pass
self.__name = name
- self.notify(self)
@property
def email(self):
@email.setter
def email(self, email):
+ try:
+ self.__oldValues['email'] = self.email
+ except AttributeError:
+ pass
self.__email = email
- self.notify(self)
@property
def username(self):
@username.setter
def username(self, username):
+ try:
+ self.__oldValues['username'] = self.username
+ except AttributeError:
+ pass
self.__username = username
- self.notify(self)
@property
def password(self):
@password.setter
def password(self, password):
+ try:
+ self.__oldValues['password'] = self.password
+ except AttributeError:
+ pass
self.__password = password
- self.notify(self)
- def __init__(self, name, email, username, password):
+ def __init__(self, name, email, username, password, id = -1):
super().__init__()
self.email = email
- self.id = -1
+ self.id = id
self.name = name
self.username = username
self.password = password
def is_anonymous(self):
return False
-
+
+ def get_id(self):
+ return self.id
+
def is_admin(self):
return self.email in ADMINS
def __repr__(self):
return '<User ID: %s Name: %s Email: %s username: %s>' % (self.id, self.name, self.email, self.username)
-class Portfolio(DB.baseorm.BaseOrm):
+class Portfolio(BaseOrm):
__tablename__ = 'portfolio'
@property
@name.setter
def name(self, name):
+ try:
+ self.__oldValues['name'] = self.name
+ except AttributeError:
+ pass
self.__name = name
@property
@public.setter
def public(self, public):
+ try:
+ self.__oldValues['public'] = self.public
+ except AttributeError:
+ pass
self.__public = public
@property
@visible.setter
def visible(self, visible):
+ try:
+ self.__oldValues['visible'] = self.visible
+ except AttributeError:
+ pass
self.__visible = visible
@property
@user.setter
def user(self, user):
+ try:
+ self.__oldValues['user'] = self.user
+ except AttributeError:
+ pass
self.__user = user
- def __init__(self, name, user):
+ def __init__(self, name, user, public = False, visible = False, id = -1):
super().__init__()
- self.id = -1
+ self.id = id
self.name = name
- self.public = False
- self.visible = False
- if not isinstance(user, User):
+ self.public = public
+ self.visible = visible
+ app.logger.info("User: {0}".format(user))
+ if (isinstance(user, User)):
+ u = user
+ else:
+ u = User(user[1], user[2], user[3], user[4], user[0])
+ if not isinstance(u, User):
raise Exception("{0}: Not a 'User'".format(user))
- self.user = user
+ self.user = u
def set_user_count(self, usercount):
self.usercount = usercount
def __repr__(self):
- return '<Portfolio Name: %s Owner: %s>' % (self.name, self.user)
+ return '<Portfolio ID: %s Name: %s Owner: %s>' % (self.id, self.name, self.user)
-class Album(DB.baseorm.BaseOrm):
+class Album(BaseOrm):
__tablename__ = 'album'
@property
@name.setter
def name(self, name):
+ try:
+ self.__oldValues['name'] = self.name
+ except AttributeError:
+ pass
self.__name = name
@property
@public.setter
def public(self, public):
+ try:
+ self.__oldValues['public'] = self.public
+ except AttributeError:
+ pass
self.__public = public
@property
@visible.setter
def visible(self, visible):
+ try:
+ self.__oldValues['visible'] = self.visible
+ except AttributeError:
+ pass
self.__visible = visible
@property
@portfolio.setter
def portfolio(self, portfolio):
+ try:
+ self.__oldValues['portfolio'] = self.portfolio
+ except AttributeError:
+ pass
self.__portfolio = portfolio
def __init__(self, name, portfolio):
def __repr__(self):
return '<Album Name: %r Portfolio: %r>' % (self.name, self.portfolio)
-class Photo(DB.baseorm.BaseOrm):
+class Photo(BaseOrm):
__tablename__ = 'photo'
@property
@name.setter
def name(self, name):
+ try:
+ self.__oldValues['name'] = self.name
+ except AttributeError:
+ pass
self.__name = name
@property
@public.setter
def public(self, public):
+ try:
+ self.__oldValues['public'] = self.public
+ except AttributeError:
+ pass
self.__public = public
@property
@visible.setter
def visible(self, visible):
+ try:
+ self.__oldValues['visible'] = self.visible
+ except AttributeError:
+ pass
self.__visible = visible
@property
@album.setter
def album(self, album):
+ try:
+ self.__oldValues['album'] = self.album
+ except AttributeError:
+ pass
self.__album = album
@property
@file.setter
def file(self, file):
+ try:
+ self.__oldValues['file'] = self.file
+ except AttributeError:
+ pass
self.__file = file
@property
@exif.setter
def exif(self, exif):
+ try:
+ self.__oldValues['exif'] = self.exif
+ except AttributeError:
+ pass
self.__exif = exif
@property
@format.setter
def format(self, format):
+ try:
+ self.__oldValues['format'] = self.format
+ except AttributeError:
+ pass
self.__format = format
def __init__(self, name, album):
def __repr__(self):
return '<Photo Name: %r File: %r Format: %r Album: %r>' % (self.name, self.file, self.format, self.album)
-class AccessRight(DB.baseorm.BaseOrm):
+class AccessRight(BaseOrm):
__tablename__ = 'accessright'
@property
@perm.setter
def perm(self, perm):
+ try:
+ self.__oldValues['perm'] = self.perm
+ except AttributeError:
+ pass
self.__perm = perm
@property
@user.setter
def user(self, user):
+ try:
+ self.__oldValues['user'] = self.user
+ except AttributeError:
+ pass
self.__user = user
def __init__(self, user):
def __repr__(self):
return '<AccessRight Right: %r User: %r>' % (self.perm, self.user)
-#class MyAnonymous(mixins.AnonymousUserMixin):
-# id = -1
-# name = 'Anonymous User'
-# email = 'no@email.com'
-# username = 'None'
-#
-# @property
-# def is_authenticated(self):
-# return False
-#
-# @property
-# def is_admin(self):
-# return False
-#
-# def get_id(self):
-# return self.id
-#
-# def __repr__(self):
-# return '<User Name: %r Email: %r username: %r>' % (self.name, self.email, self.username)
+class MyAnonymous(mixins.AnonymousUserMixin):
+ id = -1
+ name = 'Anonymous User'
+ email = 'no@email.com'
+ username = 'None'
+
+ @property
+ def is_authenticated(self):
+ return False
+
+ @property
+ def is_admin(self):
+ return False
+
+ def get_id(self):
+ return self.id
+
+ def __repr__(self):
+ return '<User Name: %r Email: %r username: %r>' % (self.name, self.email, self.username)