Beispiel #1
0
class Submission(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    competition_id = db.Column(db.Integer, db.ForeignKey('competition.id'))
    question_id = db.Column(db.Integer, db.ForeignKey('question.id'))
    answer_id = db.Column(db.Integer, nullable=True)

    def asdict(self):
        return dict(question=self.question_id, answer=self.answer_id)
Beispiel #2
0
class Question(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    text = db.Column(db.Text, nullable=False, index=True)
    created = db.Column(db.Float, default=int(now()))
    answers = db.relationship('Answers', lazy=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)

    # group_id = db.Column(db.Integer, nullable=True)

    def asdict(self, with_created=True):
        a = dict(id=self.id, text=self.text)
        if with_created:
            a['created'] = self.created
        return a

    def mixed_answers(self):
        answers = [a.asdict(with_correct=False) for a in self.answers]
        return mix(answers)

    def only_corrects(self):
        corrects = []
        for answer in self.answers:
            if answer.correct:
                corrects.append(answer.id)
        return corrects
Beispiel #3
0
class Test(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(200), nullable=False, index=True)
    description = db.Column(db.Text, nullable=True)
    owner = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)

    questions = db.relationship('Question',
                                secondary=test_questions,
                                backref=db.backref('tests', lazy=True),
                                lazy=True)
    competitions = db.relationship('Competition', lazy=True)

    def asdict(self):
        return dict(id=self.id, title=self.title, description=self.description)

    def mixed_questions(self):
        mixed = []
        for question in self.questions:
            q_dict = question.asdict(with_created=False)
            q_dict['answers'] = question.mixed_answers()
            mixed.append(q_dict)
        return mix(mixed)

    def corrects(self):
        resp = {q.id: q.only_corrects() for q in self.questions}
        return resp
Beispiel #4
0
class Competition(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(200), nullable=False, index=True)
    test_id = db.Column(db.Integer, db.ForeignKey('test.id'))
    start_date = db.Column(db.Float, index=True)
    end_date = db.Column(db.Float, index=True)
    description = db.Column(db.Text, nullable=True)
    participants = db.relationship('User',
                                   secondary=competition_participants,
                                   backref='competition',
                                   lazy='joined')
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))

    def asdict(self):
        return dict(id=self.id,
                    title=self.title,
                    test_id=self.test_id,
                    start_date=self.start_date,
                    end_date=self.end_date,
                    description=self.description)
Beispiel #5
0
class Group(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100), nullable=False, index=True)
    description = db.Column(db.Text, nullable=True)
    # TODO: many-to-many field, group_id -> array
    # group_id = db.Column(db.Integer, nullable=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=True)
    questions = db.relationship('Question', secondary=questions_groups)
    users = db.relationship('User', secondary=users_groups)

    def asdict(self):
        return dict(id=self.id, title=self.title, description=self.description)
Beispiel #6
0
class Answers(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    text = db.Column(db.Text, nullable=False)
    correct = db.Column(db.Boolean, default=False)
    question_id = db.Column(db.Integer,
                            db.ForeignKey('question.id'),
                            nullable=False)

    def asdict(self, with_correct=True):
        a = dict(id=self.id, text=self.text)
        if with_correct:
            a['correct'] = self.correct
        return a
Beispiel #7
0
from testar import db
from testar.utils import mix

test_questions = db.Table(
    'test_questions',
    db.Column('test_id',
              db.Integer,
              db.ForeignKey('test.id'),
              primary_key=True),
    db.Column('question_id',
              db.Integer,
              db.ForeignKey('question.id'),
              primary_key=True))


class Test(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(200), nullable=False, index=True)
    description = db.Column(db.Text, nullable=True)
    owner = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)

    questions = db.relationship('Question',
                                secondary=test_questions,
                                backref=db.backref('tests', lazy=True),
                                lazy=True)
    competitions = db.relationship('Competition', lazy=True)

    def asdict(self):
        return dict(id=self.id, title=self.title, description=self.description)

    def mixed_questions(self):
Beispiel #8
0
from testar import db
competition_participants = db.Table(
    'competition_participants',
    db.Column('competition',
              db.Integer,
              db.ForeignKey('competition.id'),
              primary_key=True),
    db.Column('user', db.Integer, db.ForeignKey('user.id'), primary_key=True))


class Competition(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(200), nullable=False, index=True)
    test_id = db.Column(db.Integer, db.ForeignKey('test.id'))
    start_date = db.Column(db.Float, index=True)
    end_date = db.Column(db.Float, index=True)
    description = db.Column(db.Text, nullable=True)
    participants = db.relationship('User',
                                   secondary=competition_participants,
                                   backref='competition',
                                   lazy='joined')
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))

    def asdict(self):
        return dict(id=self.id,
                    title=self.title,
                    test_id=self.test_id,
                    start_date=self.start_date,
                    end_date=self.end_date,
                    description=self.description)
Beispiel #9
0
from testar import db

questions_groups = db.Table(
    'questions_groups',
    db.Column('question',
              db.Integer,
              db.ForeignKey('question.id'),
              primary_key=True),
    db.Column('group', db.Integer, db.ForeignKey('group.id'),
              primary_key=True))

users_groups = db.Table(
    'users_groups',
    db.Column('user', db.Integer, db.ForeignKey('user.id'), primary_key=True),
    db.Column('group', db.Integer, db.ForeignKey('group.id'),
              primary_key=True))


class GroupsGroups(db.Model):
    id = db.Column(db.Integer, index=True, primary_key=True)
    group = db.Column(db.Integer, index=True)
    entry = db.Column(db.Integer, index=True)


class Group(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100), nullable=False, index=True)
    description = db.Column(db.Text, nullable=True)
    # TODO: many-to-many field, group_id -> array
    # group_id = db.Column(db.Integer, nullable=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=True)