from config import ADMINS from enum import IntEnum from baseorm import BaseOrm from flask_login import mixins from app import app class Format(IntEnum): jpg = 1 raw = 2 tiff = 3 class Role(IntEnum): read = 1 write = 2 admin = 3 class User(BaseOrm): __tablename__ = 'user' @property def name(self): return self.__name @name.setter def name(self, name): try: self.__oldValues['name'] = self.name except AttributeError: pass self.__name = name @property def email(self): return self.__email @email.setter def email(self, email): try: self.__oldValues['email'] = self.email except AttributeError: pass self.__email = email @property def username(self): return self.__username @username.setter def username(self, username): try: self.__oldValues['username'] = self.username except AttributeError: pass self.__username = username @property def password(self): return self.__password @password.setter def password(self, password): try: self.__oldValues['password'] = self.password except AttributeError: pass self.__password = password def __init__(self, name, email, username, password, id = -1): super().__init__() self.email = email self.id = id self.name = name self.username = username self.password = password def is_authenticated(self): return True def is_active(self): return True 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 '' % (self.id, self.name, self.email, self.username) class Portfolio(BaseOrm): __tablename__ = 'portfolio' @property def name(self): return self.__name @name.setter def name(self, name): try: self.__oldValues['name'] = self.name except AttributeError: pass self.__name = name @property def public(self): return self.__public @public.setter def public(self, public): try: self.__oldValues['public'] = self.public except AttributeError: pass self.__public = public @property def visible(self): return self.__visible @visible.setter def visible(self, visible): try: self.__oldValues['visible'] = self.visible except AttributeError: pass self.__visible = visible @property def user(self): return self.__user @user.setter def user(self, user): try: self.__oldValues['user'] = self.user except AttributeError: pass self.__user = user def __init__(self, name, user, public = False, visible = False, id = -1): super().__init__() self.id = id self.name = name 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 = u def set_user_count(self, usercount): self.usercount = usercount def __repr__(self): return '' % (self.id, self.name, self.user) class Album(BaseOrm): __tablename__ = 'album' @property def name(self): return self.__name @name.setter def name(self, name): try: self.__oldValues['name'] = self.name except AttributeError: pass self.__name = name @property def public(self): return self.__public @public.setter def public(self, public): try: self.__oldValues['public'] = self.public except AttributeError: pass self.__public = public @property def visible(self): return self.__visible @visible.setter def visible(self, visible): try: self.__oldValues['visible'] = self.visible except AttributeError: pass self.__visible = visible @property def portfolio(self): return self.__portfolio @portfolio.setter def portfolio(self, portfolio): try: self.__oldValues['portfolio'] = self.portfolio except AttributeError: pass self.__portfolio = portfolio def __init__(self, name, portfolio): super().__init__() self.id = -1 self.name = name self.public = False self.visible = False if not isinstance(portfolio, Portfolio): raise Exception("{0}: Not a 'Portfolio'".format(portfolio)) self.portfolio = portfolio def set_user_count(self, usercount): self.usercount = usercount def __repr__(self): return '' % (self.name, self.portfolio) class Photo(BaseOrm): __tablename__ = 'photo' @property def name(self): return self.__name @name.setter def name(self, name): try: self.__oldValues['name'] = self.name except AttributeError: pass self.__name = name @property def public(self): return self.__public @public.setter def public(self, public): try: self.__oldValues['public'] = self.public except AttributeError: pass self.__public = public @property def visible(self): return self.__visible @visible.setter def visible(self, visible): try: self.__oldValues['visible'] = self.visible except AttributeError: pass self.__visible = visible @property def album(self): return self.__album @album.setter def album(self, album): try: self.__oldValues['album'] = self.album except AttributeError: pass self.__album = album @property def file(self): return self.__file @file.setter def file(self, file): try: self.__oldValues['file'] = self.file except AttributeError: pass self.__file = file @property def exif(self): return self.__exif @exif.setter def exif(self, exif): try: self.__oldValues['exif'] = self.exif except AttributeError: pass self.__exif = exif @property def format(self): return self.__format @format.setter def format(self, format): try: self.__oldValues['format'] = self.format except AttributeError: pass self.__format = format def __init__(self, name, album): super().__init__() self.id = -1 self.name = name self.public = False self.visible = False if not isinstance(album, Album): raise Exception("{0}: Not a 'Album'".format(album)) self.album = album self.file = None self.exif = None self.format = Format.raw.value def __repr__(self): return '' % (self.name, self.file, self.format, self.album) class AccessRight(BaseOrm): __tablename__ = 'accessright' @property def perm(self): return self.__perm @perm.setter def perm(self, perm): try: self.__oldValues['perm'] = self.perm except AttributeError: pass self.__perm = perm @property def user(self): return self.__user @user.setter def user(self, user): try: self.__oldValues['user'] = self.user except AttributeError: pass self.__user = user def __init__(self, user): super().__init__() self.id = -1 self.perm = Role.read.value if not isinstance(user, User): raise Exception("{0}: Not a 'User'".format(user)) self.user = user def __repr__(self): return '' % (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 '' % (self.name, self.email, self.username)