rename all remaining pid columns to id columns

This commit is contained in:
deflax 2024-04-01 19:44:11 +03:00
parent e04867064e
commit 2aca3bee15

View file

@ -28,7 +28,7 @@ class Permission:
class Role(db.Model): class Role(db.Model):
__tablename__ = 'roles' __tablename__ = 'roles'
pid = db.Column(db.Integer, primary_key=True) id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String, unique=True) name = db.Column(db.String, unique=True)
default = db.Column(db.Boolean, default=False, index=True) default = db.Column(db.Boolean, default=False, index=True)
permissions = db.Column(db.Integer) permissions = db.Column(db.Integer)
@ -60,7 +60,7 @@ class User(db.Model, UserMixin):
active = db.Column(db.Boolean(), default=True, nullable=False) active = db.Column(db.Boolean(), default=True, nullable=False)
confirmed = db.Column(db.Boolean, default=False) confirmed = db.Column(db.Boolean, default=False)
role_id = db.Column(db.ForeignKey('roles.pid')) #FK role_id = db.Column(db.ForeignKey('roles.id')) #FK
password_hash = db.Column(db.String) password_hash = db.Column(db.String)
tokens = db.Column(db.Text) tokens = db.Column(db.Text)
@ -125,7 +125,7 @@ class User(db.Model, UserMixin):
def generate_confirmation_token(self, expiration=86400): def generate_confirmation_token(self, expiration=86400):
s = Serializer(current_app.config['SECRET_KEY'], expiration) s = Serializer(current_app.config['SECRET_KEY'], expiration)
return s.dumps({'confirm': self.pid}) return s.dumps({'confirm': self.id})
def confirm(self, token): def confirm(self, token):
s = Serializer(current_app.config['SECRET_KEY']) s = Serializer(current_app.config['SECRET_KEY'])
@ -133,7 +133,7 @@ class User(db.Model, UserMixin):
data = s.loads(token) data = s.loads(token)
except: except:
return False return False
if data.get('confirm') != self.pid: if data.get('confirm') != self.id:
return False return False
self.confirmed = True self.confirmed = True
db.session.add(self) db.session.add(self)
@ -142,7 +142,7 @@ class User(db.Model, UserMixin):
def generate_reset_token(self, expiration=86400): def generate_reset_token(self, expiration=86400):
s = Serializer(current_app.config['SECRET_KEY'], expiration) s = Serializer(current_app.config['SECRET_KEY'], expiration)
return s.dumps({'reset': self.pid}) return s.dumps({'reset': self.id})
def reset_password(self, token, new_password): def reset_password(self, token, new_password):
s = Serializer(current_app.config['SECRET_KEY']) s = Serializer(current_app.config['SECRET_KEY'])
@ -150,7 +150,7 @@ class User(db.Model, UserMixin):
data = s.loads(token) data = s.loads(token)
except: except:
return False return False
if data.get('reset') != self.pid: if data.get('reset') != self.id:
return False return False
self.password = new_password self.password = new_password
db.session.add(self) db.session.add(self)
@ -185,7 +185,7 @@ class User(db.Model, UserMixin):
return self.is_authenticated return self.is_authenticated
def get_id(self): def get_id(self):
return str(self.pid) return str(self.id)
def __repr__(self): def __repr__(self):
return '<User %r>' % self.email return '<User %r>' % self.email