]> git.datanom.net - pwp.git/blobdiff - app/models.py
Half way through migration away from sqlalchemy
[pwp.git] / app / models.py
index 3171baf191a48e7e724b3af50e7ee775859b938e..5c9f74e163610b9c60b23f27ab7c83860cb18804 100644 (file)
@@ -1,7 +1,8 @@
 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
@@ -13,7 +14,7 @@ class Role(IntEnum):
     write = 2
     admin = 3
 
-class User(DB.baseorm.BaseOrm):
+class User(BaseOrm):
     __tablename__ = 'user'
     
     @property
@@ -22,8 +23,11 @@ class User(DB.baseorm.BaseOrm):
 
     @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):
@@ -31,8 +35,11 @@ class User(DB.baseorm.BaseOrm):
 
     @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):
@@ -40,8 +47,11 @@ class User(DB.baseorm.BaseOrm):
 
     @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):
@@ -49,13 +59,16 @@ class User(DB.baseorm.BaseOrm):
 
     @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
@@ -68,14 +81,17 @@ class User(DB.baseorm.BaseOrm):
 
     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
@@ -84,6 +100,10 @@ class Portfolio(DB.baseorm.BaseOrm):
 
     @name.setter
     def name(self, name):
+        try:
+            self.__oldValues['name'] = self.name
+        except AttributeError:
+            pass
         self.__name = name
 
     @property
@@ -92,6 +112,10 @@ class Portfolio(DB.baseorm.BaseOrm):
         
     @public.setter
     def public(self, public):
+        try:
+            self.__oldValues['public'] = self.public
+        except AttributeError:
+            pass
         self.__public = public
         
     @property
@@ -100,6 +124,10 @@ class Portfolio(DB.baseorm.BaseOrm):
         
     @visible.setter
     def visible(self, visible):
+        try:
+            self.__oldValues['visible'] = self.visible
+        except AttributeError:
+            pass
         self.__visible = visible
         
     @property
@@ -108,25 +136,34 @@ class Portfolio(DB.baseorm.BaseOrm):
         
     @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
@@ -135,6 +172,10 @@ class Album(DB.baseorm.BaseOrm):
 
     @name.setter
     def name(self, name):
+        try:
+            self.__oldValues['name'] = self.name
+        except AttributeError:
+            pass
         self.__name = name
 
     @property
@@ -143,6 +184,10 @@ class Album(DB.baseorm.BaseOrm):
         
     @public.setter
     def public(self, public):
+        try:
+            self.__oldValues['public'] = self.public
+        except AttributeError:
+            pass
         self.__public = public
         
     @property
@@ -151,6 +196,10 @@ class Album(DB.baseorm.BaseOrm):
         
     @visible.setter
     def visible(self, visible):
+        try:
+            self.__oldValues['visible'] = self.visible
+        except AttributeError:
+            pass
         self.__visible = visible
         
     @property
@@ -159,6 +208,10 @@ class Album(DB.baseorm.BaseOrm):
         
     @portfolio.setter
     def portfolio(self, portfolio):
+        try:
+            self.__oldValues['portfolio'] = self.portfolio
+        except AttributeError:
+            pass
         self.__portfolio = portfolio
         
     def __init__(self, name, portfolio):
@@ -177,7 +230,7 @@ class Album(DB.baseorm.BaseOrm):
     def __repr__(self):
         return '<Album Name: %r Portfolio: %r>' % (self.name,  self.portfolio)
 
-class Photo(DB.baseorm.BaseOrm):
+class Photo(BaseOrm):
     __tablename__ = 'photo'
 
     @property
@@ -186,6 +239,10 @@ class Photo(DB.baseorm.BaseOrm):
 
     @name.setter
     def name(self, name):
+        try:
+            self.__oldValues['name'] = self.name
+        except AttributeError:
+            pass
         self.__name = name
 
     @property
@@ -194,6 +251,10 @@ class Photo(DB.baseorm.BaseOrm):
         
     @public.setter
     def public(self, public):
+        try:
+            self.__oldValues['public'] = self.public
+        except AttributeError:
+            pass
         self.__public = public
         
     @property
@@ -202,6 +263,10 @@ class Photo(DB.baseorm.BaseOrm):
         
     @visible.setter
     def visible(self, visible):
+        try:
+            self.__oldValues['visible'] = self.visible
+        except AttributeError:
+            pass
         self.__visible = visible
         
     @property
@@ -210,6 +275,10 @@ class Photo(DB.baseorm.BaseOrm):
         
     @album.setter
     def album(self, album):
+        try:
+            self.__oldValues['album'] = self.album
+        except AttributeError:
+            pass
         self.__album = album
         
     @property
@@ -218,6 +287,10 @@ class Photo(DB.baseorm.BaseOrm):
 
     @file.setter
     def file(self, file):
+        try:
+            self.__oldValues['file'] = self.file
+        except AttributeError:
+            pass
         self.__file = file
 
     @property
@@ -226,6 +299,10 @@ class Photo(DB.baseorm.BaseOrm):
 
     @exif.setter
     def exif(self, exif):
+        try:
+            self.__oldValues['exif'] = self.exif
+        except AttributeError:
+            pass
         self.__exif = exif
 
     @property
@@ -234,6 +311,10 @@ class Photo(DB.baseorm.BaseOrm):
         
     @format.setter
     def format(self, format):
+        try:
+            self.__oldValues['format'] = self.format
+        except AttributeError:
+            pass
         self.__format = format
         
     def __init__(self, name, album):
@@ -252,7 +333,7 @@ class Photo(DB.baseorm.BaseOrm):
     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
@@ -261,6 +342,10 @@ class AccessRight(DB.baseorm.BaseOrm):
 
     @perm.setter
     def perm(self, perm):
+        try:
+            self.__oldValues['perm'] = self.perm
+        except AttributeError:
+            pass
         self.__perm = perm
 
     @property
@@ -269,6 +354,10 @@ class AccessRight(DB.baseorm.BaseOrm):
         
     @user.setter
     def user(self, user):
+        try:
+            self.__oldValues['user'] = self.user
+        except AttributeError:
+            pass
         self.__user = user
 
     def __init__(self, user):
@@ -282,22 +371,22 @@ class AccessRight(DB.baseorm.BaseOrm):
     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)
This page took 0.070162 seconds and 5 git commands to generate.