Ejemplo n.º 1
0
class Event(db.Model):
    __tablename__ = 'events'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(250), nullable=False)
    description = db.Column(db.String(255), nullable=False)
    start_date = db.Column(db.Date, nullable=False)
    project_id = db.Column(db.Integer, db.ForeignKey('projects.id'))
    project = db.relationship('Project', backref=db.backref('events'))
    users = db.relationship('User', secondary=events_users)

    def __repr__(self):
        text = "Event: \t{}\n\t\tDescription: {}\n\t\tDay: {}"
        return text.format(self.name, self.description, self.start_date)
Ejemplo n.º 2
0
class Project(db.Model):
    __tablename__ = 'projects'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(100), nullable=False)
    description = db.Column(db.Text, nullable=False)
    start_date = db.Column(db.Date, nullable=False)
    end_date = db.Column(db.Date, nullable=False)
    image = db.Column(db.LargeBinary)
    location = db.Column(db.String(200), nullable=False)
    contact_phone = db.Column(db.String(15), nullable=False)
    manager_id = db.Column(db.Integer, db.ForeignKey('users.id'))
    manager = db.relationship('User', uselist=False)
    users = db.relationship('User',
                              secondary=users_projects)

    def __repr__(self):
        return "Project: {} \nDescription: {}".format(self.name, self.description)
Ejemplo n.º 3
0
class User(db.Model):
    __tablename__ = 'users'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    full_name = db.Column(db.String(250), nullable=False)
    email = db.Column(db.String(255), nullable=False)
    phone_number = db.Column(db.String(9), nullable=False)
    abilities = db.Column(db.Text(), nullable=True)
    availability = db.Column(db.Text(), nullable=True)
    tools = db.Column(db.Text(), nullable=True)
    materials = db.Column(db.Text(), nullable=True)

    projects = db.relationship('Project', secondary=users_projects)

    def __repr__(self):
        text = "User: \t{}\n\t\tEmail: {}\n\t\tPhone Number: {}"
        return text.format(self.full_name, self.email, self.phone_number)
Ejemplo n.º 4
0
class User(db.Model):
    __tablename__ = 'users'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    full_name = db.Column(db.String(250), nullable=False)
    email = db.Column(db.String(255), nullable=False)
    phone_number = db.Column(db.String(9), nullable=True, default='')
    abilities = db.Column(db.Text(), nullable=True)
    availability = db.Column(db.Text(), nullable=True)
    tools = db.Column(db.Text(), nullable=True)
    materials = db.Column(db.Text(), nullable=True)
    projects = db.relationship('Project', secondary=users_projects)
    events = db.relationship('Event', secondary=events_users)

    # Login related properties and methods
    _hashed_password = db.Column(db.Binary(HASH_SIZE), nullable=False)
    _salt = db.Column(db.Binary(HASH_SIZE),
                      nullable=False,
                      default=os.urandom(HASH_SIZE))

    @property
    def hashed_password(self):
        return self._hashed_password

    def _generate_hashed_password(self, password):
        if not self._salt:
            self._salt = os.urandom(HASH_SIZE)
        return hashlib.sha256(self._salt +
                              bytes(password, encoding='utf8')).digest()

    def store_password_hashed(self, password):
        hashed_password = self._generate_hashed_password(password)
        self._hashed_password = hashed_password

    def test_password(self, password):
        password_under_test = self._generate_hashed_password(password)
        return password_under_test == self._hashed_password

    def is_authenticated(self):
        return True

    _active = db.Column(db.Boolean, default=True)

    def is_active(self):
        return self._active

    def activate(self):
        self._active = True

    def is_anonymous(self):
        return False

    def get_id(self):
        return str(self.id)

    # auth methods
    _is_admin = db.Column(db.Boolean, nullable=False, default=False)

    #manages = db.relationship('Projects')

    def is_admin(self):
        return self._is_admin

    def is_manager(self):
        # change when properly add a manager to a project.
        return self._is_admin

    def __repr__(self):
        text = "User: \t{}\n\t\tEmail: {}\n\t\tPhone Number: {}"
        return text.format(self.full_name, self.email, self.phone_number)