Ejemplo n.º 1
0
class User(db.Model):
    __tablename__ = "user"
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    category = db.Column(db.String(50), nullable=False)
    phone_number = db.Column(db.String(50))
    email = db.Column(db.String(50), unique=True, nullable=False)
    address_id = db.Column(db.Integer,
                           db.ForeignKey('address.id'),
                           nullable=False)
    address = db.relationship("Address",
                              backref=db.backref("user", uselist=False))
    user_name = db.Column(db.String(50), unique=True, nullable=False)
    password_hash = db.Column(db.String(256), nullable=False)

    __mapper_args__ = {
        "polymorphic_identity": __tablename__,
        "polymorphic_on": category,
    }

    def __init__(self, user_name, password, category, phone_number, email):
        self.user_name = user_name
        self.password_hash = self.generate_hash(password)
        self.category = category
        self.phone_number = phone_number
        self.email = email

    @staticmethod
    def generate_hash(password):
        return pbkdf2_sha256.hash(password.encode("utf8"))

    @staticmethod
    def verify_hash(password, hashed_password):
        return pbkdf2_sha256.verify(password.encode("utf8"), hashed_password)
class OpenInternship(db.Model):
    __tablename__ = "open_internship"

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    internship_code = db.Column(db.String(50), unique=True, nullable=False)
    company_id = db.Column(db.ForeignKey("company.id"), nullable=False)
    company = db.relationship("Company",
                              backref=db.backref(__tablename__, uselist=False))
    title = db.Column(db.String(250), nullable=False)
    description = db.Column(db.String(350), nullable=False)
    required_cgpa = db.Column(db.String(30), nullable=False)
    comments = db.Column(db.String(300))
    start_date = db.Column(db.Date, nullable=False)
    end_date = db.Column(db.Date, nullable=False)

    def __init__(self, internship_code, company_id, title, description,
                 required_cgpa, comments, start_date, end_date):
        self.internship_code = internship_code
        self.company_id = company_id
        self.title = title
        self.description = description
        self.required_cgpa = required_cgpa
        self.comments = comments
        self.start_date = start_date
        self.end_date = end_date
Ejemplo n.º 3
0
class Token(db.Model):
    id = db.Column(db.Integer, primary_key=True)

    hash = db.Column(db.String(255))
    expiration_date = db.Column(db.DateTime)

    user_id = db.Column(db.Integer, db.ForeignKey('users.id'))

    def __init__(self, user, hash, expiration_date):
        self.user = user
        self.hash = hash
        self.expiration_date = expiration_date
Ejemplo n.º 4
0
class Student(User):
    __tablename__ = "student"
    id = db.Column(db.ForeignKey("user.id"), primary_key=True)
    first_name = db.Column(db.String(30), nullable=False)
    middle_name = db.Column(db.String(30), nullable=False)
    last_name = db.Column(db.String(30), nullable=False)
    registration_id = db.Column(db.String(50), unique=True, nullable=False)

    program_id = db.Column(db.Integer,
                           db.ForeignKey('program.id'),
                           nullable=False)
    program = db.relationship("Program",
                              backref=db.backref(__tablename__, uselist=False))

    __mapper_args__ = {"polymorphic_identity": __tablename__}

    def __init__(self, user_name, password, phone_number, email, first_name,
                 middle_name, last_name, registration_id):
        super().__init__(user_name, password, "student", phone_number, email)
        self.first_name = first_name
        self.middle_name = middle_name
        self.last_name = last_name
        self.registration_id = registration_id
Ejemplo n.º 5
0
class Company(User):
    __tablename__ = "company"
    id = db.Column(db.ForeignKey("user.id"), primary_key=True)
    name = db.Column(db.String(50), nullable=False)
    __mapper_args__ = {"polymorphic_identity": __tablename__}
    company_code = db.Column(db.String(50), unique=True, nullable=False)

    def __init__(self, user_name, password, phone_number, email, name,
                 company_code):
        super().__init__(user_name, password, "company", phone_number, email)
        self.name = name
        self.company_code = company_code

    def __repr__(self):
        return "Company %s" % self.name
Ejemplo n.º 6
0
class Internship(db.Model):
    __tablename__ = "internship"
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    internship_id = db.Column(db.ForeignKey("open_internship.id"),
                              nullable=False)
    internship_details = db.relationship("OpenInternship",
                                         backref=db.backref(__tablename__,
                                                            uselist=False))

    university_id = db.Column(db.ForeignKey("university.id"), nullable=False)
    university = db.relationship("University",
                                 backref=db.backref(__tablename__,
                                                    uselist=False))

    student_id = db.Column(db.ForeignKey("student.id"), nullable=False)
    student = db.relationship("Student",
                              backref=db.backref(__tablename__, uselist=False))
    status = db.Column(db.String(30), nullable=False)

    def __init__(self, internship_id, university_id, student_id, status):
        self.internship_id = internship_id
        self.university_id = university_id
        self.student_id = student_id
        self.status = status
Ejemplo n.º 7
0
class Performance(db.Model):
    id = db.Column(db.Integer, primary_key=True)

    departure_loc = db.Column(db.Integer)
    arrival_loc = db.Column(db.Integer)
    departure_time = db.Column(db.DateTime)
    arrival_time = db.Column(db.DateTime)
    distance = db.Column(db.Float)
    mean_speed = db.Column(db.Float)

    user_id = db.Column(db.Integer, db.ForeignKey('users.id'))

    def __init__(self, user, departure_loc, departure_time, distance):
        self.user = user
        self.departure_loc = departure_loc
        self.departure_time = departure_time
        self.distance = distance
Ejemplo n.º 8
0
class University(User):
    __tablename__ = "university"
    id = db.Column(db.ForeignKey("user.id"), primary_key=True)
    name = db.Column(db.String(150), nullable=False)
    university_code = db.Column(db.String(50), unique=True, nullable=False)

    programs = db.relationship("Program",
                               secondary="university_program",
                               backref="universities")

    __mapper_args__ = {"polymorphic_identity": __tablename__}

    def __init__(self, user_name, password, phone_number, email, name,
                 university_code):
        super().__init__(user_name, password, "university", phone_number,
                         email)
        self.name = name
        self.university_code = university_code

    def __repr__(self):
        return ("University Name %s, " % (self.name))
from model.base import db

university_program = db.Table(
    'university_program', db.metadata,
    db.Column('university_id',
              db.Integer,
              db.ForeignKey('university.id'),
              nullable=False),
    db.Column('program_id',
              db.Integer,
              db.ForeignKey('program.id'),
              nullable=False))
Ejemplo n.º 10
0
from model.base import db
from flask.ext.restful import fields

user_marshaller = {
    'id': fields.Integer,
    'email': fields.String
}

user_bookmarks = db.Table('user_bookmarks',
                          db.Column('user_id', db.Integer,
                                    db.ForeignKey('users.id')),
                          db.Column('station_number', db.Integer,
                                    db.ForeignKey('station.number'))
                          )


class User(db.Model):
    __tablename__ = 'users'
    id = db.Column(db.Integer, primary_key=True)

    email = db.Column(db.String(120), unique=True)
    password = db.Column(db.String(128))

    performances = db.relationship('Performance', backref='user')
    tokens = db.relationship('Token', backref='user')

    bookmarks = db.relationship('Station', secondary=user_bookmarks,
                                backref='users')

    def __init__(self, email, password):
        self.email = email