Пример #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
Пример #3
0
class Station(db.Model):
    number = db.Column(db.Integer, primary_key=True)

    name = db.Column(db.String(127))
    address = db.Column(db.String(255))
    position = db.Column(Geography(geometry_type='POINT', srid=4326))
    banking = db.Column(db.Boolean)
    bonus = db.Column(db.Boolean)
    status = db.Column(db.String(10))
    bike_stands = db.Column(db.Integer)
    available_bike_stands = db.Column(db.Integer)
    available_bikes = db.Column(db.Integer)
    last_update = db.Column(db.DateTime)

    def __init__(self, number, name, address, position, banking, bonus, status,
                 bike_stands, available_bike_stands, available_bikes,
                 last_update):
        self.number = number
        self.name = name
        self.address = address
        self.position = position
        self.banking = banking
        self.bonus = bonus
        self.status = status
        self.bike_stands = bike_stands
        self.available_bike_stands = available_bike_stands
        self.available_bikes = available_bikes
        self.last_update = last_update
Пример #4
0
class Poi():
    name = db.Column(db.String(127))
    address = db.Column(db.String(255))
    position = db.Column(Geography(geometry_type='POINT', srid=4326))

    def __init__(self, name, address, position):
        self.name = name
        self.address = address
        self.position = position
Пример #5
0
class Program(db.Model):
    __tablename__ = "program"
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(100), nullable=False)
    program_code = db.Column(db.String(50), unique=True, nullable=False)

    def __init__(self, name, program_code):
        self.name = name
        self.program_code = program_code

    def __repr__(self):
        return "Program Name %s" % self.name
Пример #6
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
Пример #7
0
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
        self.password = password
Пример #8
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
Пример #9
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))
Пример #10
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
Пример #11
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
Пример #12
0
class Address(db.Model):
    __tablename__ = "address"
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    address_line1 = db.Column(db.String(100), nullable=False)
    address_line2 = db.Column(db.String(100))
    city = db.Column(db.String(50), nullable=False)
    province = db.Column(db.String(50), nullable=False)
    country = db.Column(db.String(50), nullable=False)
    zip_code = db.Column(db.String(50), nullable=False)

    def __init__(self, address_line1, address_line2, city, province, country,
                 zip_code):
        self.address_line1 = address_line1
        self.address_line2 = address_line2
        self.city = city
        self.province = province
        self.country = country
        self.zip_code = zip_code

    def __repr__(self):
        return "Address %s" % self.name