コード例 #1
0
ファイル: models.py プロジェクト: marshall62/partner
class Group(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    roster_id = db.Column(db.Integer, db.ForeignKey('roster.id'))
    date = db.Column(db.Date)
    members = db.relationship('Student',
                              secondary=group2student,
                              lazy='subquery',
                              backref=db.backref('groups', lazy=True))

    def to_dict(self):
        return {
            'id': self.id,
            'roster_id': self.roster_id,
            'date': self.date,
            'members': [s.to_dict() for s in self.members]
        }

    def __eq__(self, other):
        return self.id == other.id

    def __repr__(self):
        mems = ""
        for s in self.members:
            mems += s.__repr__() + ","
        return "<Group {} {} >".format(self.id, mems[:-1])
コード例 #2
0
ファイル: models.py プロジェクト: marshall62/partner
class Roster(db.Model):
    tablename__ = 'roster'
    id = db.Column(db.Integer, primary_key=True)
    section_id = db.Column(db.Integer, db.ForeignKey('section.id'))
    section = db.relationship("Section", back_populates="roster")
    students = db.relationship('Student', backref='student', lazy='dynamic')

    def to_dict(self, students=None):
        d = {
            'lab_num':
            self.section.number,
            'section_id':
            self.section_id,
            'year':
            self.section.year,
            'title':
            self.section.full_title,
            'term':
            self.section.term,
            'students': [
                s.to_dict()
                for s in (self.students if not students else students)
            ]
        }
        return d

    def sorted_students(self):
        l = list(self.students)
        l.sort()
        return l

    def __repr__(self):
        return '{} <Lab-{} {} {} {}>'.format(self.id, self.section.number,
                                             self.section.year, self.term,
                                             self.section.title)
コード例 #3
0
ファイル: models.py プロジェクト: marshall62/partner
class AttendanceEntry(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    timestamp = db.Column(db.DateTime, index=True, default=datetime.utcnow)
    date = db.Column(db.Date, index=True)
    value = db.Column(db.String(12), default='P')
    stud_id = db.Column(db.Integer, db.ForeignKey('student.id'))

    def __repr__(self):
        return '<Entry {} {}>'.format(self.date, self.value)
コード例 #4
0
ファイル: models.py プロジェクト: marshall62/partner
class Student(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    onecard_id = db.Column(db.String(12), index=True, unique=True)
    first_name = db.Column(db.String(64), index=True)
    last_name = db.Column(db.String(64), index=True)
    nick_name = db.Column(db.String(64), index=True)
    email = db.Column(db.String(120), index=True, unique=True)
    attendance = db.relationship('AttendanceEntry',
                                 backref='attendance',
                                 lazy='dynamic')
    class_id = db.Column(db.Integer, db.ForeignKey('roster.id'))
    status = ''

    def __lt__(self, other):
        return self.last_name < other.last_name

    @property
    def pic_url(self):
        url = ''
        if self.onecard_id:
            url = "https://www.smith.edu/load.php?pic=" + self.onecard_id
        return url

    @property
    def preferred_fname(self):
        if self.nick_name:
            return self.nick_name
        else:
            return self.first_name

    def to_dict(self):
        return {
            'id': self.id,
            'onecard_id': self.onecard_id,
            'pic_url': self.pic_url,
            'full_name': self.preferred_fname + ' ' + self.last_name,
            'preferred_fname': self.preferred_fname,
            'first_name': self.first_name,
            'nick_name': self.nick_name,
            'last_name': self.last_name,
            'status': self.status
        }

    def __repr__(self):
        return '<{} {} {} {} {} class:{}>'.format(self.id, self.onecard_id,
                                                  self.first_name,
                                                  self.nick_name,
                                                  self.last_name,
                                                  self.class_id)
コード例 #5
0
ファイル: models.py プロジェクト: marshall62/partner
    def sorted_students(self):
        l = list(self.students)
        l.sort()
        return l

    def __repr__(self):
        return '{} <Lab-{} {} {} {}>'.format(self.id, self.section.number,
                                             self.section.year, self.term,
                                             self.section.title)


group2student = db.Table(
    'group2student',
    db.Column('group_id',
              db.Integer,
              db.ForeignKey('group.id'),
              primary_key=True),
    db.Column('student_id',
              db.Integer,
              db.ForeignKey('student.id'),
              primary_key=True))


class Group(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    roster_id = db.Column(db.Integer, db.ForeignKey('roster.id'))
    date = db.Column(db.Date)
    members = db.relationship('Student',
                              secondary=group2student,
                              lazy='subquery',
                              backref=db.backref('groups', lazy=True))