예제 #1
0
class AreaModel(db.Model):
    __tablename__ = 'Areas'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    area_name = db.Column(db.String(150), unique=True, nullable=False)
    graduate_programs = db.relationship('GraduateProgramModel',
                                        lazy='select',
                                        backref=db.backref('area',
                                                           lazy='joined'))

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

    def appendPrograms(self, programs):
        for program in programs:
            self.graduate_programs.append(program)

    @property
    def serialized(self):
        return {
            "area_id":
            self.id,
            "area_name":
            self.area_name,
            "area_programs":
            [program.serialized for program in self.graduate_programs]
        }

    def __repr__(self):
        return '<AreaModel %r>' % (self.area_name)
예제 #2
0
class UserModel(db.Model):
    __tablename__ = 'Users'

    id = db.Column(db.String(50), primary_key=True)
    email = db.Column(db.String(120), unique=True, nullable=False)
    password = db.Column(db.String(150), nullable=False)
    fullname = db.Column(db.String(200), nullable=False)
    role_id = db.Column(db.Integer, db.ForeignKey('Roles.id'), nullable=False)

    admissions = db.relationship('AdmissionModel',
                                 lazy='select',
                                 backref=db.backref('user', lazy='joined'))

    def __init__(self, id, email, password, fullname, user_role):
        self.id = id
        self.email = email
        self.password = password
        self.fullname = fullname

        # This field exist because of the backref of its relational table.
        self.role = user_role

    def __repr__(self):
        return '<UserModel %r>' % (self.email)

    @property
    def serialized(self):
        return {
            "id": self.id,
            "email": self.email,
            "fullname": self.fullname,
            "role": self.role.role_name
        }
예제 #3
0
class SubjectModel(db.Model):
    __tablename__ = "Subjects"

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    subject_name = db.Column(db.String(200), nullable=False, unique=True)
    subject_credits = db.Column(db.Integer, nullable=False)
    hours_per_week = db.Column(db.Integer, nullable=False)
    amount_of_weeks = db.Column(db.Integer, nullable=False)
    subject_semester = db.Column(db.Integer, nullable=False)

    program_id = db.Column(db.Integer,
                           db.ForeignKey('Graduate_Programs.id'),
                           nullable=False)

    admissions = db.relationship('AdmissionSubjectRelation',
                                 lazy='select',
                                 backref=db.backref('subject', lazy='joined'))

    def __init__(self, name, credits, hours, weeks, semester):
        self.subject_name = name
        self.subject_credits = credits
        self.hours_per_week = hours
        self.amount_of_weeks = weeks
        self.subject_semester = semester

    @property
    def serialized(self):
        return {
            "id": self.id,
            "name": self.subject_name,
            "credits": self.subject_credits,
            "hours_per_week": self.hours_per_week,
            "weeks": self.amount_of_weeks,
            "subject_semester": self.subject_semester
        }
예제 #4
0
class AdmissionModel(db.Model):
    __tablename__ = 'Admissions'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    user_id = db.Column(db.String(50),
                        db.ForeignKey('Users.id'),
                        nullable=False)
    program_id = db.Column(db.Integer,
                           db.ForeignKey('Graduate_Programs.id'),
                           nullable=False)
    status_id = db.Column(db.Integer,
                          db.ForeignKey('Admission_Statuses.id'),
                          nullable=False)
    current_semester = db.Column(db.Integer, nullable=False)

    subjects = db.relationship('AdmissionSubjectRelation',
                               lazy='select',
                               backref=db.backref('admission', lazy='joined'))

    def __init__(self, userid, programid, statusid):
        self.user_id = userid
        self.program_id = programid
        self.status_id = statusid
        self.current_semester = 0

    @property
    def serialized(self):
        return {
            "admission_id": self.id,
            "user_email": self.user.email,
            "program_name": self.program.program_name,
            "status": self.status.status_name,
            "current_semester": self.current_semester,
            "type": self.program.type.type_name
        }
class GraduateProgramModel(db.Model):
    __tablename__ = 'Graduate_Programs'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    program_name = db.Column(db.String(200), nullable=False)
    area_id = db.Column(db.Integer, db.ForeignKey('Areas.id'), nullable=False)
    type_id = db.Column(db.Integer,
                        db.ForeignKey('Program_Types.id'),
                        nullable=False)
    degree_id = db.Column(db.Integer,
                          db.ForeignKey('Degree_Types.id'),
                          nullable=False)

    subjects = db.relationship('SubjectModel',
                               lazy='select',
                               backref=db.backref('program', lazy='joined'))

    admissions = db.relationship('AdmissionModel',
                                 lazy='select',
                                 backref=db.backref('program', lazy='joined'))

    def __init__(self, name, program_type, program_degree):
        self.program_name = name

        # These variables exist because of the backref of their relational tables.
        self.type = program_type
        self.degree = program_degree

    def appendSubjects(self, new_subjects):
        for subject in new_subjects:
            self.subjects.append(subject)

    @property
    def serialized(self):
        return {
            "program_id": self.id,
            "program_name": self.program_name,
            "area_id": self.area_id,
            "area_name": self.area.area_name,
            "type_name": self.type.type_name,
            "degree_type": self.degree.degree_name
        }

    def __repr__(self):
        return '<GraduateProgramModel %r>' % (self.program_name)
예제 #6
0
class AdmissionStatusModel(db.Model):
    __tablename__ = 'Admission_Statuses'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    status_name = db.Column(db.String(50), nullable=False, unique=True)

    admissions = db.relationship('AdmissionModel',
                                 lazy='select',
                                 backref=db.backref('status', lazy='joined'))

    def __init__(self, name):
        self.status_name = name
class ProgramTypeModel(db.Model):
    __tablename__ = 'Program_Types'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    type_name = db.Column(db.String(50), nullable=False, unique=True)
    
    programs = db.relationship('GraduateProgramModel',
        lazy='select',
        backref=db.backref('type', lazy='joined'))

    def __init__(self, name):
        self.type_name = name
예제 #8
0
class SubjectStatusModel(db.Model):
    __tablename__ = "Subject_Statuses"

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    status_name = db.Column(db.String(50), unique=True, nullable=False)

    admission_subjects = db.relationship('AdmissionSubjectRelation',
        lazy='select',
        backref=db.backref('status', lazy='joined'))

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

    @property
    def serialized(self):
        return {
            "id": self.id,
            "name": self.status_name
        }
예제 #9
0
class RoleModel(db.Model):
    __tablename__ = 'Roles'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    role_name = db.Column(db.String(100), unique=True, nullable=False)
    users = db.relationship('UserModel', lazy='select', backref=db.backref('role', lazy='joined'))

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

    def __repr__(self):
        return '<RoleModel %r>' % (self.role_name)

    @property
    def serialized(self):
        return {
            "id": self.id,
            "name": self.role_name
        }
예제 #10
0
class DegreeModel(db.Model):
    __tablename__ = 'Degree_Types'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    degree_name = db.Column(db.String(200), nullable=False, unique=True)

    programs = db.relationship('GraduateProgramModel',
                               lazy='select',
                               backref=db.backref('degree', lazy='joined'))

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

    def appendPrograms(self, new_programs):
        for program in new_programs:
            self.programs.append(program)

    def __repr__(self):
        return '<DegreeModel %r>' % (self.degree_name)

    @property
    def serialized(self):
        return {"id": self.id, "degree_name": self.degree_name}