Example #1
0
class TopicTree(db.Model):
    id = db.Column(db.Integer(), primary_key=True)
    subject = db.Column(db.Integer(), db.ForeignKey('subject.id'))
    #represents the json tree representation {'parent_topic' : {'child_topic' : {'grandchild_topic' : None, 'grandchild_topic2' : None}}}
    tree_representation = db.Column(db.String(1000), nullable=False)
    def __unicode__(self):
        return self.tree_representation
Example #2
0
class Course(db.Model):
    id = db.Column(db.Integer(), primary_key=True)
    subject = db.Column(db.Integer(), db.ForeignKey('subject.id'))
    number = db.Column(db.String(60), nullable=False)
    school = db.Column(db.Integer(), db.ForeignKey('school.id'))
    def __unicode__(self):
        return unicode(self.subject) + " " + self.number
Example #3
0
class ContentToTopic(db.Model):
    id = db.Column(db.Integer(), primary_key=True)
    content = db.Column(db.Text(), nullable = False)
    links = db.Column(db.Text(), nullable = False, default = '')
    topic = db.Column(db.Integer(), db.ForeignKey('topic.id'))
    version_number = db.Column(db.Integer(), nullable = False)
    def __unicode__(self):
        return unicode(self.topic) + "'s content"
Example #4
0
class DiscussionPost(db.Model):
    id = db.Column(db.Integer(), primary_key=True)
    text = db.Column(db.Text(), nullable = False)
    user = db.Column(db.Integer(), db.ForeignKey('user.id'))
    date_time = db.Column(db.DateTime(), nullable = False)
    topic = db.Column(db.Integer(), db.ForeignKey('topic.id'))
    ups = db.Column(db.Integer(), nullable = False, default = 0)
    downs = db.Column(db.Integer(), nullable = False, default = 0)
    deleted = db.Column(db.Boolean(), nullable=False, default = False)
    def __unicode__(self):
        return unicode(self.user) + " posted " + unicode(self.text) + " to " + unicode(self.topic)
Example #5
0
class Comment(db.Model):
    id = db.Column(db.Integer(), primary_key=True)
    comment = db.Column(db.Text(), nullable = False)
    date_time = db.Column(db.DateTime(), nullable = False)
    ip = db.Column(db.String(30), nullable=False)
    email = db.Column(db.String(60), nullable=False)
    def __unicode__(self):
        if self.email:
            return self.email + ' sent ' + self.comment
        else:
            return self.comment
Example #6
0
class User(db.Model, UserMixin):
    id = db.Column(db.Integer(), primary_key=True)
    email = db.Column(db.String(120), index=True, unique=True, nullable=False)
    firstname = db.Column(db.String(30), index=True, nullable=False)
    lastname = db.Column(db.String(30), index=True, nullable=False)
    password = db.Column(db.String(255), nullable=False)
    active = db.Column(db.Boolean())
    website = db.Column(db.String(120))
    confirmed_at = db.Column(db.DateTime())
    roles = db.relationship('Role',
                            secondary=roles_users,
                            backref=db.backref('user', lazy='dynamic'))
    grades = db.relationship('Grade', lazy='dynamic', backref='user')
    programs = db.relationship('Program', lazy='dynamic', backref='user')
    code_revisions = db.relationship('CodeRevision',
                                     lazy='dynamic',
                                     backref='user')
    submissions = db.relationship('Submission', lazy='dynamic', backref='user')

    def is_admin(self):
        return self.has_role("admin")

    def add_grade(self, assignment, score):
        grade = Grade(score=score)
        self.grades.append(grade)
        assignment.grades.append(grade)
        db.session.add(grade)
        db.session.commit()

    def get_grade(self, assignment):
        grades = self.grades.filter_by(assignment_id=assignment.id).all()
        if len(grades) == 0:
            grade = self.grades.filter_by(assignment_id=assignment.id).all()[0]
            return grade
        else:
            return None
Example #7
0
class Role(db.Model, RoleMixin):
    id = db.Column(db.Integer(), primary_key=True)
    name = db.Column(db.String(80), unique=True)
    description = db.Column(db.String(255))
Example #8
0
from application_config import app, db
from flask.ext.security import RoleMixin, UserMixin, SQLAlchemyUserDatastore

roles_users = db.Table(
    'roles_users', db.Column('user_id', db.Integer(),
                             db.ForeignKey('user.id')),
    db.Column('role_id', db.Integer(), db.ForeignKey('role.id')))


class Role(db.Model, RoleMixin):
    id = db.Column(db.Integer(), primary_key=True)
    name = db.Column(db.String(80), unique=True)
    description = db.Column(db.String(255))


class User(db.Model, UserMixin):
    id = db.Column(db.Integer(), primary_key=True)
    email = db.Column(db.String(120), index=True, unique=True, nullable=False)
    firstname = db.Column(db.String(30), index=True, nullable=False)
    lastname = db.Column(db.String(30), index=True, nullable=False)
    password = db.Column(db.String(255), nullable=False)
    active = db.Column(db.Boolean())
    website = db.Column(db.String(120))
    confirmed_at = db.Column(db.DateTime())
    roles = db.relationship('Role',
                            secondary=roles_users,
                            backref=db.backref('user', lazy='dynamic'))
    grades = db.relationship('Grade', lazy='dynamic', backref='user')
    programs = db.relationship('Program', lazy='dynamic', backref='user')
    code_revisions = db.relationship('CodeRevision',
                                     lazy='dynamic',
Example #9
0
class TopicToCourse(db.Model):
    id = db.Column(db.Integer(), primary_key=True)
    topic = db.Column(db.Integer(), db.ForeignKey('topic.id'))
    course = db.Column(db.Integer(), db.ForeignKey('course.id'))
    def __unicode__(self):
        return unicode(self.course) + " has this topic: " + unicode(self.topic)
Example #10
0
class TopicToSubject(db.Model):
    id = db.Column(db.Integer(), primary_key=True)
    topic = db.Column(db.Integer(), db.ForeignKey('topic.id'))
    subject = db.Column(db.Integer(), db.ForeignKey('subject.id'))
    def __unicode__(self):
        return unicode(self.subject) + "'s " + unicode(self.topic)
Example #11
0
class Topic(db.Model):
    id = db.Column(db.Integer(), primary_key=True)
    topic_name = db.Column(db.String(200), nullable=False)
    title = db.Column(db.String(200), nullable=False)
    def __unicode__(self):
        return self.topic_name
Example #12
0
class Subject(db.Model):
    id = db.Column(db.Integer(), primary_key=True)
    name = db.Column(db.String(200), nullable=False)
    def __unicode__(self):
        return self.name
Example #13
0
class School(db.Model):
    id = db.Column(db.Integer(), primary_key=True)
    name = db.Column(db.String(100), index=True, nullable=False)