haldis/app/models/user.py

39 lines
992 B
Python
Raw Normal View History

from models import db
class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(80), unique=True, nullable=False)
admin = db.Column(db.Boolean)
bias = db.Column(db.Integer)
2019-09-05 03:33:29 +02:00
runs = db.relation(
"Order",
backref="courrier",
primaryjoin="Order.courrier_id==User.id",
foreign_keys="Order.courrier_id",
)
orderItems = db.relationship("OrderItem", backref="user", lazy="dynamic")
2019-09-08 00:41:50 +02:00
def configure(self, username: str, admin: bool, bias: int) -> None:
self.username = username
self.admin = admin
self.bias = bias
2019-09-08 00:41:50 +02:00
def is_authenticated(self) -> bool:
return True
2019-09-08 00:41:50 +02:00
def is_active(self) -> bool:
return True
2019-09-08 00:41:50 +02:00
def is_admin(self) -> bool:
return self.admin
2019-09-08 00:41:50 +02:00
def is_anonymous(self) -> bool:
return False
2019-09-08 00:41:50 +02:00
def get_id(self) -> str:
2019-08-31 00:50:01 +02:00
return str(self.id)
2019-09-08 00:41:50 +02:00
def __repr__(self) -> str:
2019-09-05 03:33:29 +02:00
return "%s" % self.username