示例#1
0
class Employee(TimestampsMixin, DB.Model):
    """Model for employee business entity."""
    __tablename__ = "employees"

    id = DB.Column(DB.Integer, primary_key=True, autoincrement=True)
    first_name = DB.Column(DB.String, nullable=False)
    last_name = DB.Column(DB.String, nullable=False)
    username = DB.Column(DB.String(15), unique=True, nullable=False)
    phone_number = DB.Column(DB.String, nullable=False)
    birth_date = DB.Column(DB.Date(), nullable=False)
    registration_date = DB.Column(DB.DateTime(), nullable=False)
    account_status = DB.Column(DB.String, nullable=False)
    user_status = DB.Column(DB.String, nullable=False)
    email = DB.Column(DB.String(300), nullable=False)
    password = DB.Column(DB.String(300), nullable=False)
    pin_code = DB.Column(DB.Integer, unique=True, nullable=False)
    comment = DB.Column(DB.String)
    company_id = DB.Column(DB.Integer, DB.ForeignKey("companies.id"))
    role_id = DB.Column(DB.Integer, DB.ForeignKey("roles.id"), nullable=True)

    company = DB.relationship("Company", back_populates="employees")
    items = DB.relationship("Item", back_populates="empolyee")
    history = DB.relationship("ItemHistory", back_populates="employee")
    role = DB.relationship("Role", back_populates="employees")

    def __repr__(self):
        return "<Employee(username=%s)>" % self.username
示例#2
0
class Employee(TimestampsMixin, DB.Model):
    """Model for employee business entity.
    @todo #4:30min Continue implementation. Employees should have its own
     management pages to list, create, edit and delete them. In the index page
     it should be possible to sort and filter for every column. Other possible
     actions are described in more detail in issue #4. Specific details about
     Employee default values are in another puzzle.
    @todo #4:30min Implement validate_required decorator for all the models in
     the timeless app that require mandatory parameters check. See Employee
     model as an example of how to use the decorator. Write tests to verify
     all the mandatory fields are checked.
    """
    __tablename__ = "employees"

    id = DB.Column(DB.Integer, primary_key=True, autoincrement=True)
    first_name = DB.Column(DB.String, nullable=False)
    last_name = DB.Column(DB.String, nullable=False)
    username = DB.Column(DB.String(15), unique=True, nullable=False)
    phone_number = DB.Column(DB.String, nullable=False)
    birth_date = DB.Column(DB.Date(), nullable=False)
    registration_date = DB.Column(DB.DateTime(), nullable=False)
    account_status = DB.Column(DB.String, nullable=False)
    user_status = DB.Column(DB.String, nullable=False)
    email = DB.Column(DB.String(300), nullable=False)
    password = DB.Column(DB.String(300), nullable=False)
    pin_code = DB.Column(DB.Integer, unique=True, nullable=False)
    comment = DB.Column(DB.String)
    company_id = DB.Column(DB.Integer, DB.ForeignKey("companies.id"))

    company = DB.relationship("Company", back_populates="employees")
    items = DB.relationship("Item", back_populates="empolyee")
    history = DB.relationship("ItemHistory", back_populates="employee")

    @validate_required("username", "password", "first_name", "last_name",
                       "phone_number", "birth_date", "email")
    def __init__(self, **kwargs):
        super(Employee, self).__init__(**kwargs)
        self.password = bcrypt_sha256.hash(kwargs.get("password"))
        self.pin_code = randint(1000, 9999)
        self.registration_date = datetime.utcnow()
        self.account_status = "Not Activated"
        self.user_status = "Working"
        self.created_on = datetime.utcnow()

    def __repr__(self):
        return "<Employee(username=%s)>" % self.username

    def validate_password(self, password):
        """ Validate user password """
        return bcrypt_sha256.verify(password, self.password)
示例#3
0
class Employee(TimestampsMixin, DB.Model):
    """Model for employee business entity.
    @todo #4:30min Continue implementation. Employees should have its own
     management pages to list, create, edit and delete them. In the index page
     it should be possible to sort and filter for every column. Other possible
     actions are described in more detail in issue #4. Specific details about
     Employee default values are in another puzzle.
    """
    __tablename__ = "employees"

    id = DB.Column(DB.Integer, primary_key=True, autoincrement=True)
    first_name = DB.Column(DB.String, nullable=False)
    last_name = DB.Column(DB.String, nullable=False)
    username = DB.Column(DB.String(15), unique=True, nullable=False)
    phone_number = DB.Column(DB.String, nullable=False)
    birth_date = DB.Column(DB.Date(), nullable=False)
    registration_date = DB.Column(DB.DateTime(), nullable=False)
    account_status = DB.Column(DB.String, nullable=False)
    user_status = DB.Column(DB.String, nullable=False)
    email = DB.Column(DB.String(300), nullable=False)
    password = DB.Column(DB.String(300), nullable=False)
    pin_code = DB.Column(DB.Integer, unique=True, nullable=False)
    comment = DB.Column(DB.String)
    company_id = DB.Column(DB.Integer, DB.ForeignKey("companies.id"))
    role_id = DB.Column(DB.Integer, DB.ForeignKey("roles.id"), nullable=True)

    company = DB.relationship("Company", back_populates="employees")
    items = DB.relationship("Item", back_populates="empolyee")
    history = DB.relationship("ItemHistory", back_populates="employee")

    @validate_required("username", "password", "first_name", "last_name",
                       "phone_number", "birth_date", "email", "pin_code",
                       "registration_date", "account_status", "user_status")
    def __init__(self, **kwargs):
        super(Employee, self).__init__(**kwargs)

    def __repr__(self):
        return "<Employee(username=%s)>" % self.username

    def validate_password(self, password):
        """ Validate user password """
        return bcrypt_sha256.verify(password, self.password)
示例#4
0
class Employee(TimestampsMixin, DB.Model):
    """Model for employee business entity."""
    __tablename__ = "employees"

    id = DB.Column(DB.Integer, primary_key=True, autoincrement=True)
    first_name = DB.Column(DB.String, nullable=False)
    last_name = DB.Column(DB.String, nullable=False)
    username = DB.Column(DB.String(15), unique=True, nullable=False)
    phone_number = DB.Column(DB.String, nullable=False)
    birth_date = DB.Column(DB.Date(), nullable=False)
    registration_date = DB.Column(DB.DateTime(), nullable=False)
    account_status = DB.Column(DB.String, nullable=False)
    user_status = DB.Column(DB.String, nullable=False)
    email = DB.Column(DB.String(300), nullable=False)
    password = DB.Column(DB.String(300), nullable=False)
    pin_code = DB.Column(DB.Integer, unique=True, nullable=False)
    comment = DB.Column(DB.String)
    company_id = DB.Column(DB.Integer, DB.ForeignKey("companies.id"))
    role_id = DB.Column(DB.Integer, DB.ForeignKey("roles.id"), nullable=True)

    company = DB.relationship("Company", back_populates="employees")
    items = DB.relationship("Item", back_populates="empolyee")
    history = DB.relationship("ItemHistory", back_populates="employee")

    @validate_required("username", "password", "first_name", "last_name",
                       "phone_number", "birth_date", "email", "pin_code",
                       "registration_date", "account_status", "user_status")
    def __init__(self, **kwargs):
        super(Employee, self).__init__(**kwargs)

    def __repr__(self):
        return "<Employee(username=%s)>" % self.username

    def validate_password(self, password):
        """ Validate user password """
        return bcrypt_sha256.verify(password, self.password)