Esempio n. 1
0
class Post(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(50), nullable=False)
    question = db.Column(db.BLOB, nullable=False)
    type = db.Column(db.String(20), nullable=False, server_default='auto')
    steps = relationship('Step',
                         back_populates='post',
                         cascade='all, delete-orphan')
    answers = relationship('Answer',
                           back_populates='post',
                           cascade='all, delete-orphan')
    creation_date = db.Column(db.DateTime, nullable=False)
    last_edit_date = db.Column(db.DateTime)
    user_id = db.Column(db.Integer, ForeignKey('user.id'))
    user = relationship('User', back_populates='posts')
    homework_id = db.Column(db.Integer, ForeignKey('homework.id'))
    homework = relationship('Homework', back_populates='posts')

    def __str__(self):
        return """Question Title: {0}
Step Count: {1}""".format(self.title, len(self.steps))

    def info(self):
        return """Title: {6}
Question: {0}
Steps: {1}
Created: {2}
Last Edited: {3}
User: {4}
Homework: {5}""".format(self.question, self.steps, self.creation_date,
                        self.last_edit_date, self.user, self.homework,
                        self.title)
Esempio n. 2
0
class Course(db.Model):
    id = db.Column('id', db.Integer, primary_key=True)
    subject = db.Column('subject', db.String(100), nullable=False)
    number = db.Column('number', db.Integer, nullable=False)
    professor_name = db.Column('professor_name',
                               db.String(200),
                               nullable=False)
    course_times = db.Column('course_times', db.String(100), nullable=False)
    homeworks = relationship('Homework', back_populates='course')
    school_id = db.Column(db.Integer, ForeignKey('school.id'))
    school = relationship('School', back_populates='courses')

    def __str__(self):
        return '{0} {1} at {2} -- {3}, {4}'.format(self.subject,
                                                   str(self.number),
                                                   self.course_times,
                                                   self.professor_name,
                                                   self.school.full_name)

    def info(self):
        buf = self.__str__() + '\n'
        buf += 'Homeworks:\n'
        for hw in self.homeworks:
            buf += str(hw)
        return buf
Esempio n. 3
0
class Homework(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100), nullable=False)
    posts = relationship('Post',
                         back_populates='homework',
                         cascade='all, delete-orphan')
    due_date = db.Column('due_date', db.DateTime)
    course_id = db.Column(db.Integer, ForeignKey('course.id'))
    course = relationship('Course', back_populates='homeworks')

    def __str__(self):
        return self.title

    def info(self):
        buf = self.title + '\n'
        buf += 'Due Date: ' + str(self.due_date) + '\n'
        if not self.course is None:
            buf += 'Course: {0} {1}'.format(self.course.subject,
                                            self.course.number)
        buf += 'Posts:\n'
        for post in self.posts:
            buf += str(post) + '\n'

        return buf

    def pretty_date(self):
        return self.due_date.strftime('%a, %b %d, %Y at %I:%M %p')
Esempio n. 4
0
class School(db.Model):
    id = db.Column('id', db.Integer, primary_key=True)
    full_name = db.Column('full_name', db.String(200), nullable=False)
    short_name = db.Column('short_name', db.String(100))
    courses = relationship('Course', back_populates='school')

    def __str__(self):
        return self.full_name

    def info(self):
        buf = '{0} ({1})'.format(self.full_name, self.short_name) + '\n'
        for course in self.courses:
            buf += '{0} {1} on {2} -- {3}'.format(
                course.subject, course.number, course.course_times,
                course.professor_name) + '\n'
        return buf
Esempio n. 5
0
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(20), unique=True, nullable=False)
    email = db.Column(db.String(150), unique=True, nullable=False)
    password = db.Column(db.String(50), nullable=False)
    is_admin = db.Column('is_admin', db.Integer, server_default='0')
    posts = relationship('Post', back_populates='user')

    def __str__(self):
        return "{0}\n".format(self.username)

    def info(self):
        buf = """Username: {0}
Email: {1}
Admin: {2}
""".format(self.username, self.email, self.is_admin)
        buf += 'Posts:\n'
        for post in self.posts:
            buf += post.question + '\n'

        return buf