Exemplo n.º 1
0
class Course(db.Model):
    __tablename__ = 'courses'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String())
    details = db.Column(db.String())
    prof_id = db.Column(db.Integer,
                        db.ForeignKey('professors.id'),
                        nullable=False)
    course_code = db.Column(db.String(), unique=True)
    branches = db.relationship('Branch',
                               secondary=branch_helper,
                               backref=db.backref('courses'))
    can_apply = db.Column(db.Boolean)
    courseNotes = db.relationship('courseNote',
                                  backref='Course',
                                  order_by="desc(courseNote.time)")
    assignments = db.relationship('Assignment',
                                  backref='Course',
                                  order_by="desc(Assignment.time)")
    requests = db.relationship('Request', backref='course')
    quizzes = db.relationship('Quiz', backref='course')

    def __init__(
        self,
        name,
        course_code,
        details,
        prof_id,
        can_apply,
    ):
        self.name = name
        self.course_code = course_code
        self.details = details
        self.prof_id = prof_id
        self.can_apply = can_apply
Exemplo n.º 2
0
class Course(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(50), nullable=False)
    crd_hrs = db.Column(db.Integer)
    no_of_student_taken = db.Column(db.Integer, default=0)
    status = db.Column(db.String(10))

    assign_to = db.Column(db.Integer, db.ForeignKey('teacher.id'))
    enrollments = db.relationship('Student',
                                  secondary=Enrollments,
                                  backref=db.backref('courses'))

    def __repr__(self):
        return f'Course :  {self.id} , {self.name}'
Exemplo n.º 3
0
class User(db.Model, UserMixin):
    __tablename__ = 'users'
    name = db.Column(db.String(100), nullable=False)
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100))
    email = db.Column(db.String(64), unique=True, index=True)
    password_hash = db.Column(db.String(128))
    year = db.Column(db.Integer())
    branch_id = db.Column(db.Integer,
                          db.ForeignKey('branches.id'),
                          nullable=False)
    courses = db.relationship('Course',
                              secondary=course_helper,
                              backref=db.backref('students'))
    submissions = db.relationship('Submission', backref='user')
    requests = db.relationship('Request', backref='user')
    quiz_responses = db.relationship('QuizResponse', backref='user')

    def __init__(self, name, email, password, year, branch_id):
        self.name = name
        self.email = email
        self.password_hash = generate_password_hash(password)
        self.year = year
        self.branch_id = branch_id

    def to_dict(self):
        return {
            'id': self.id,
            'Name': self.name,
            'E-Mail': self.email,
            'Year': self.year,
            'Branch': self.branch.name
        }

    def check_password(self, password):
        return check_password_hash(self.password_hash, password)

    @property
    def requested_courses(self):
        req_courses = []
        for request in self.requests:
            req_courses.append(request.course)
        return req_courses