Ejemplo n.º 1
0
class User(Entity, db.Model, UserMixin):
    email = db.Column(db.String(255), unique=True)
    name = db.Column(db.String(80))
    password = db.Column(db.String(60))
    active = db.Column(db.Boolean, default=True)
    roles = db.relationship('Role', secondary=roles_users, backref=db.backref('users', lazy='dynamic'))
    complaint_by = db.relationship(
        'Complaint', foreign_keys='Complaint.complaint_by', backref='complaint_user', lazy=True
    )
    responded_by = db.relationship(
        'Complaint', foreign_keys='Complaint.responded_by', backref='responded_user', lazy=True
    )

    last_login_at = db.Column(db.DateTime(), nullable=True)
    current_login_at = db.Column(db.DateTime(), nullable=True)
    last_login_ip = db.Column(db.String(255), nullable=True)
    current_login_ip = db.Column(db.String(255), nullable=True)
    login_count = db.Column(db.Integer, nullable=True, default=0)

    def __init__(self, last_updated_by='system', **kwargs):
        super().__init__(last_updated_by)
        self.email = kwargs['email']
        self.name = kwargs['name']
        self.password = kwargs['password']

    def __setattr__(self, key, value):
        if key == 'password':
            value = jwt.hash_password(value)
        super().__setattr__(key, value)

    def get_security_payload(self):
        return get_security_payload_dto(self)

    @property
    def rolenames(self):
        return list(row.name for row in self.roles)

    @classmethod
    def lookup(cls, username):
        return cls.query.filter_by(email=username).one_or_none()

    @classmethod
    def identify(cls, id):
        return cls.query.get(id)

    @property
    def identity(self):
        return self.id

    def is_valid(self):
        return self.active

    def __repr__(self):
        return '<User[email=%s]>' % self.email
Ejemplo n.º 2
0
class ProposalAuthor(Entity, db.Model):
    name = db.Column(db.String(80))
    email = db.Column(db.String(255))
    phone_number = db.Column(db.String(15), nullable=True)
    organisation_name = db.Column(db.String(255), nullable=True)
    status = db.Column(db.Boolean, default=True)
    projects = db.relationship('Project', backref='proposal_authors', lazy=True)
    email_logs = db.relationship('EmailLog', backref='proposal_authors', lazy=True)

    def __init__(self, last_updated_by='system', **kwargs):
        super().__init__(last_updated_by)
        self.email = kwargs['email']
        self.name = kwargs['name']
        self.phone_number = kwargs.get('phone_number', None)
        self.organisation_name = kwargs.get('organisation_name', None)
Ejemplo n.º 3
0
class Project(Entity, db.Model):
    proposal_author = db.Column(db.Integer,
                                db.ForeignKey('proposal_author.id'),
                                nullable=False)
    title = db.Column(db.String(255))
    description = db.Column(db.Text)
    file_name = db.Column(db.String(255), nullable=True)
    deadline = db.Column(db.DateTime, nullable=True)
    city = db.Column(db.String(255))
    country = db.Column(db.String(255))
    platform = db.Column(db.String(255), nullable=True)
    availability = db.Column(db.String(255), nullable=True)
    category = db.relationship('ProjectCategory',
                               secondary=project_to_category,
                               backref=db.backref('projects', lazy='dynamic'))
    status = db.Column(db.String(50), default="PROPOSED")
    students = db.relationship('Student', backref='projects', lazy=True)

    def __init__(self, last_updated_by='system', **kwargs):
        super().__init__(last_updated_by)
        self.title = kwargs['title']
        self.description = kwargs['description']
        self.proposal_author = kwargs['proposal_author']
        self.city = kwargs['city']
        self.country = kwargs['country']
        self.deadline = kwargs.get('deadline', None)
        self.platform = kwargs.get('platform', None)
        self.availability = kwargs.get('availability', None)
Ejemplo n.º 4
0
class EmailLog(Entity, db.Model):
    body = db.Column(db.Text)
    subject = db.Column(db.String(255))
    email_to = db.Column(db.String(255))
    status = db.Column(db.Boolean, default=True)
    project = db.Column(db.Integer, db.ForeignKey('project.id'), nullable=True)
    sent_by = db.Column(db.Integer, db.ForeignKey('staff.id'), nullable=False)
    student = db.Column(db.Integer, db.ForeignKey('student.id'), nullable=True)
    proposal_author = db.Column(db.Integer, db.ForeignKey('proposal_author.id'), nullable=True)

    def __init__(self, last_updated_by='system', **kwargs):
        super().__init__(last_updated_by)
        self.subject = kwargs.get('subject', None)
        self.body = kwargs.get('body', None)
        self.email_to = kwargs.get('email_to', None)
        self.sent_by = kwargs.get('sent_by', None)
        self.student = kwargs.get('student', None)
        self.proposal_author = kwargs.get('proposal_author', None)
        self.project = kwargs.get('project', None)
Ejemplo n.º 5
0
class Entity(object):
    id = db.Column(db.Integer, primary_key=True)
    created_at = db.Column(db.DateTime)
    updated_at = db.Column(db.DateTime)
    last_updated_by = db.Column(db.String(255))

    def __init__(self, last_updated_by):
        self.created_at = datetime.now()
        self.updated_at = datetime.now()
        self.last_updated_by = last_updated_by

    def __setattr__(self, key, value):
        if key == 'updated_at':
            value = datetime.now()
        super().__setattr__(key, value)
Ejemplo n.º 6
0
class Comment(Entity, db.Model):
    project = db.Column(db.Integer, db.ForeignKey('project.id'), nullable=True)
    student = db.Column(db.Integer, db.ForeignKey('student.id'), nullable=True)
    text = db.Column(db.Text)
    project_status = db.Column(db.String(50), nullable=True)
    sent_email = db.Column(db.BOOLEAN, default=False)
    status = db.Column(db.Boolean, default=True)
    commented_by = db.Column(db.Integer,
                             db.ForeignKey('staff.id'),
                             nullable=False)

    def __init__(self, last_updated_by='system', **kwargs):
        super().__init__(last_updated_by)
        self.text = kwargs['text']
        self.project = kwargs.get('project', None)
        self.student = kwargs.get('student', None)
        self.project_status = kwargs.get('project_status', None)
        self.sent_email = kwargs.get('sent_email', False)
        self.commented_by = kwargs['commented_by']
Ejemplo n.º 7
0
class Complaint(Entity, db.Model):
    title = db.Column(db.String(50))
    text = db.Column(db.Text)
    address = db.Column(db.Text)
    city = db.Column(db.String(255))
    state = db.Column(db.String(255))
    country = db.Column(db.String(255))
    pin_code = db.Column(db.Integer)
    vehicle_number = db.Column(db.String(15))
    vehicle_details = db.Column(db.Text)
    file_name = db.Column(db.String(255), nullable=True)
    complaint_status = db.Column(db.String(50), default='PENDING')
    complaint_by = db.Column(db.Integer,
                             db.ForeignKey('user.id'),
                             nullable=False)
    responded_by = db.Column(db.Integer,
                             db.ForeignKey('user.id'),
                             nullable=True,
                             default=None)
    response_details = db.Column(db.Text, nullable=True, default=None)
    status = db.Column(db.Boolean, default=True)

    def __init__(self, last_updated_by='system', **kwargs):
        super().__init__(last_updated_by)
        self.title = kwargs['title']
        self.text = kwargs['text']
        self.address = kwargs['address']
        self.vehicle_number = kwargs['vehicle_number']
        self.vehicle_details = kwargs['vehicle_details']
        self.city = kwargs['city']
        self.state = kwargs['state']
        self.country = kwargs['country']
        self.pin_code = kwargs['pin_code']
        self.file_name = kwargs.get('file_name', None)
        self.complaint_status = kwargs.get('complaint_status', None)
        self.complaint_by = kwargs['complaint_by']
        self.responded_by = kwargs.get('responded_by', None)
Ejemplo n.º 8
0
class Student(Entity, db.Model):
    name = db.Column(db.String(80))
    email = db.Column(db.String(255))
    phone_number = db.Column(db.String(15), nullable=True)
    description = db.Column(db.Text)
    city = db.Column(db.String(255))
    country = db.Column(db.String(255))
    is_in_team = db.Column(db.Boolean, default=False)
    status = db.Column(db.String(15), default='INTERESTED')
    project = db.Column(db.Integer,
                        db.ForeignKey('project.id'),
                        nullable=False)
    comments = db.relationship('Comment', backref='students', lazy=True)
    email_logs = db.relationship('EmailLog', backref='students', lazy=True)

    def __init__(self, last_updated_by='system', **kwargs):
        super().__init__(last_updated_by)
        self.email = kwargs['email']
        self.name = kwargs['name']
        self.project = kwargs['project']
        self.phone_number = kwargs.get('phone_number', None)
        self.description = kwargs.get('description', None)
        self.city = kwargs.get('city', None)
        self.country = kwargs.get('country', None)
Ejemplo n.º 9
0
class Role(db.Model, RoleMixin):
    id = db.Column(db.Integer(), primary_key=True)
    name = db.Column(db.String(80), unique=True)
    description = db.Column(db.String(255))
    status = db.Column(db.Boolean, default=True)
Ejemplo n.º 10
0
class ProjectCategory(db.Model):
    id = db.Column(db.Integer(), primary_key=True)
    name = db.Column(db.String(80), unique=True)
    description = db.Column(db.String(255), nullable=True)
    status = db.Column(db.Boolean, default=True)