add new columns in user model, (active and phantom fields)

This commit is contained in:
Cayo Puigdefabregas 2021-04-08 19:13:28 +02:00
parent a9ec5de237
commit 9a43ab0097
1 changed files with 9 additions and 3 deletions

View File

@ -2,7 +2,7 @@ from uuid import uuid4
from citext import CIText from citext import CIText
from flask import current_app as app from flask import current_app as app
from sqlalchemy import Column from sqlalchemy import Column, Boolean
from sqlalchemy.dialects.postgresql import UUID from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy_utils import EmailType, PasswordType from sqlalchemy_utils import EmailType, PasswordType
@ -21,6 +21,8 @@ class User(Thing):
**kwargs **kwargs
))) )))
token = Column(UUID(as_uuid=True), default=uuid4, unique=True, nullable=False) token = Column(UUID(as_uuid=True), default=uuid4, unique=True, nullable=False)
active = Column(Boolean, default=True, nullable=False)
phantom = Column(Boolean, default=False, nullable=False)
inventories = db.relationship(Inventory, inventories = db.relationship(Inventory,
backref=db.backref('users', lazy=True, collection_class=set), backref=db.backref('users', lazy=True, collection_class=set),
secondary=lambda: UserInventory.__table__, secondary=lambda: UserInventory.__table__,
@ -28,16 +30,20 @@ class User(Thing):
# todo set restriction that user has, at least, one active db # todo set restriction that user has, at least, one active db
def __init__(self, email, password=None, inventories=None) -> None: def __init__(self, email, password=None, inventories=None, active=True, phantom=False) -> None:
"""Creates an user. """Creates an user.
:param email: :param email:
:param password: :param password:
:param inventories: A set of Inventory where the user has :param inventories: A set of Inventory where the user has
access to. If none, the user is granted access to the current access to. If none, the user is granted access to the current
inventory. inventory.
:param active: allow active and deactive one account without delete the account
:param phantom: it's util for identify the phantom accounts
create during the trade actions
""" """
inventories = inventories or {Inventory.current} inventories = inventories or {Inventory.current}
super().__init__(email=email, password=password, inventories=inventories) super().__init__(email=email, password=password, inventories=inventories,
active=active, phantom=phantom)
def __repr__(self) -> str: def __repr__(self) -> str:
return '<User {0.email}>'.format(self) return '<User {0.email}>'.format(self)