Exemplo n.º 1
0
from riddle import app, db, model_classes
from peewee import *
from riddle.models.Question import Question
from flask_peewee.admin import ModelAdmin


class Option(db.Model):
    text = TextField()
    question = ForeignKeyField(Question)

    def __unicode__(self):
        return self.text

    def as_json(self):
        return {'text': self.text}


class OptionAdmin(ModelAdmin):
    columns = ('text', 'question')


model_classes.append((Option, OptionAdmin))
Exemplo n.º 2
0
from riddle import app, db, model_classes
from peewee import *
from riddle.models.Questionnaire import Questionnaire
from flask_peewee.admin import ModelAdmin

class Comment(db.Model):
    author = CharField()
    subject = CharField()
    body = TextField()
    questionnaire = ForeignKeyField(Questionnaire)
    datetime = DateTimeField()

class CommentAdmin(ModelAdmin):
    columns = ('subject', 'body', 'questionnaire')

model_classes.append((Comment, CommentAdmin))
Exemplo n.º 3
0
from riddle import app, db, model_classes
from peewee import *
from riddle.models.Question import Question
from flask_peewee.admin import ModelAdmin

class Option(db.Model):
    text = TextField()
    question = ForeignKeyField(Question)

    def __unicode__(self):
        return self.text

    def as_json(self):
      return {
        'text': self.text
      }

class OptionAdmin(ModelAdmin):
    columns = ('text', 'question')

model_classes.append((Option, OptionAdmin))

Exemplo n.º 4
0
from riddle import app, db, model_classes
from peewee import *
from riddle.models.Teacher import Teacher
from flask_peewee.admin import ModelAdmin


class Category(db.Model):
    name = CharField()
    teacher = ForeignKeyField(Teacher)

    def __unicode__(self):
        return self.name


class CategoryAdmin(ModelAdmin):
    columns = ('name', 'teacher')


model_classes.append((Category, CategoryAdmin))
Exemplo n.º 5
0
from flask_peewee.admin import ModelAdmin

class Questionnaire(db.Model):
    name = CharField()
    public_id = CharField()
    category = ForeignKeyField(Category)

    def __unicode__(self):
        return "%s (ID: %s)" % (self.name, self.public_id)

    def presented_question(self):
        Question = riddle.models.Question.Question
        try:
            return Question.select().where(Question.questionnaire == self, Question.presented == True).get()
        except Question.DoesNotExist:
            return None

    class Meta:
        indexes = (
            (('public_id',), True),
            (('name', 'category'), False)
        )

class QuestionnaireAdmin(ModelAdmin):
    columns = ('name', 'public_id', 'category')


model_classes.append((Questionnaire, QuestionnaireAdmin))


Exemplo n.º 6
0
from riddle import app, db, model_classes
from peewee import *
from riddle.models.Questionnaire import Questionnaire
from riddle.models.Student import Student
from flask_peewee.admin import ModelAdmin


class Rating(db.Model):
    like = BooleanField()
    student = ForeignKeyField(Student)
    questionnaire = ForeignKeyField(Questionnaire)


class RatingAdmin(ModelAdmin):
    columns = ('like', 'questionnaire')


model_classes.append((Rating, RatingAdmin))
Exemplo n.º 7
0
from riddle import app, db, model_classes
from peewee import *
from riddle.models.Question import Question
from riddle.models.Option import Option
from riddle.models.Student import Student
from flask_peewee.admin import ModelAdmin


class Answer(db.Model):
    text = TextField(null=True)
    option = ForeignKeyField(Option, null=True)
    question = ForeignKeyField(Question)
    student = ForeignKeyField(Student)


class AnswerAdmin(ModelAdmin):
    columns = ('id', 'text', 'option', 'student')


model_classes.append((Answer, AnswerAdmin))
Exemplo n.º 8
0
            'questionnaire_id': self.questionnaire.id,
            'last_ping': self.last_ping
        })

    @classmethod
    def update_latest(cls, student, questionnaire):
        now = datetime.now()
        try:
            pres = cls.get(cls.student == student,
                           cls.questionnaire == questionnaire)
            pres.last_ping = now
        except cls.DoesNotExist:
            pres = cls(student=student,
                       questionnaire=questionnaire,
                       last_ping=now)
        pres.save()

    @classmethod
    def count_active(cls, questionnaire):
        reference_time = datetime.now() + timedelta(seconds=-15)
        query = cls.select().where(cls.questionnaire == questionnaire,
                                   cls.last_ping > reference_time)
        return query.count()


class StudentPresenceAdmin(ModelAdmin):
    columns = ('student_id', 'questionnaire_id', 'last_ping')


model_classes.append((StudentPresence, StudentPresenceAdmin))
Exemplo n.º 9
0
from riddle import app, db, model_classes
from peewee import *
from riddle.models.Teacher import Teacher
from flask_peewee.admin import ModelAdmin

class Category(db.Model):
    name = CharField()
    teacher = ForeignKeyField(Teacher)

    def __unicode__(self):
        return self.name

class CategoryAdmin(ModelAdmin):
    columns = ('name', 'teacher')

model_classes.append((Category, CategoryAdmin))

Exemplo n.º 10
0
    questionnaire = ForeignKeyField(Questionnaire)

    def __unicode__(self):
        return self.description

    def present(self):
        """Presents question while un-presenting all other questions in questionnaire"""
        Question.update(presented=False).where(
            Question.questionnaire == self.questionnaire).execute()
        self.presented = True
        self.save()

    def options(self):
        from riddle.models.Option import Option
        return [o for o in Option.select().where(Option.question == self)]

    def as_json(self):
        return {
            'description': self.description,
            'type': self.typ,
            'presented': self.presented,
            'options': [o.as_json() for o in self.options()]
        }


class QuestionAdmin(ModelAdmin):
    columns = ('description', 'typ', 'presented', 'questionnaire', 'id')


model_classes.append((Question, QuestionAdmin))
Exemplo n.º 11
0
from riddle import app, db, model_classes
from peewee import *
from riddle.models.Questionnaire import Questionnaire
from flask_peewee.admin import ModelAdmin


class Comment(db.Model):
    author = CharField()
    subject = CharField()
    body = TextField()
    questionnaire = ForeignKeyField(Questionnaire)
    datetime = DateTimeField()


class CommentAdmin(ModelAdmin):
    columns = ('subject', 'body', 'questionnaire')


model_classes.append((Comment, CommentAdmin))
Exemplo n.º 12
0
from riddle import app, db, model_classes
from peewee import *
from riddle.models.Question import Question
from riddle.models.Option import Option
from riddle.models.Student import Student
from flask_peewee.admin import ModelAdmin

class Answer(db.Model):
    text = TextField(null=True)
    option = ForeignKeyField(Option, null=True)
    question = ForeignKeyField(Question)
    student = ForeignKeyField(Student)

class AnswerAdmin(ModelAdmin):
    columns = ('id', 'text', 'option', 'student')

model_classes.append((Answer, AnswerAdmin))
Exemplo n.º 13
0
    active = BooleanField()
    superuser = BooleanField()

    def __unicode__(self):
        return '%s (%s)' % (self.username, self.fullname)

    def as_json(self):
        return {
            'username': self.username,
            'fullname': self.fullname,
            'email': self.email
        }


class TeacherAdmin(ModelAdmin):
    columns = ('username', 'fullname', 'password', 'superuser')

    def save_model(self, instance, form, adding=False):
        orig_password = instance.password

        user = super(TeacherAdmin, self).save_model(instance, form, adding)

        if orig_password != form.password.data:
            user.set_password(form.password.data)
            user.save()

        return user


model_classes.append((Teacher, TeacherAdmin))
Exemplo n.º 14
0
from riddle import app, db, model_classes
from peewee import *
from riddle.models.Questionnaire import Questionnaire
from riddle.models.Student import Student
from flask_peewee.admin import ModelAdmin

class Rating(db.Model):
    like = BooleanField()
    student = ForeignKeyField(Student)
    questionnaire = ForeignKeyField(Questionnaire)

class RatingAdmin(ModelAdmin):
    columns = ('like', 'questionnaire')

model_classes.append((Rating, RatingAdmin))
Exemplo n.º 15
0
    def to_json(self):
      return json.dumps({
        'student_id': self.student.id,
        'questionnaire_id': self.questionnaire.id,
        'last_ping': self.last_ping
      })

    @classmethod
    def update_latest(cls, student, questionnaire):
      now = datetime.now()
      try:
        pres = cls.get(cls.student == student, cls.questionnaire == questionnaire)
        pres.last_ping = now
      except cls.DoesNotExist:
        pres = cls(student=student, questionnaire=questionnaire, last_ping=now)
      pres.save()

    @classmethod
    def count_active(cls, questionnaire):
      reference_time = datetime.now() + timedelta(seconds=-15)
      query = cls.select().where(cls.questionnaire == questionnaire, cls.last_ping > reference_time)
      return query.count()



class StudentPresenceAdmin(ModelAdmin):
    columns = ('student_id', 'questionnaire_id', 'last_ping')

model_classes.append((StudentPresence, StudentPresenceAdmin))

Exemplo n.º 16
0
    superuser = BooleanField()

    def __unicode__(self):
        return '%s (%s)' % (self.username, self.fullname)

    def as_json(self):
        return {
            'username': self.username,
            'fullname': self.fullname,
            'email': self.email
        }

class TeacherAdmin(ModelAdmin):
    columns = ('username', 'fullname', 'password', 'superuser')

    def save_model(self, instance, form, adding=False):
        orig_password = instance.password

        user = super(TeacherAdmin, self).save_model(instance, form, adding)

        if orig_password != form.password.data:
            user.set_password(form.password.data)
            user.save()

        return user


model_classes.append((Teacher, TeacherAdmin))


Exemplo n.º 17
0
    questionnaire = ForeignKeyField(Questionnaire)

    def __unicode__(self):
        return self.description

    def present(self):
        """Presents question while un-presenting all other questions in questionnaire"""
        Question.update(presented=False).where(Question.questionnaire == self.questionnaire).execute()
        self.presented = True
        self.save()

    def options(self):
        from riddle.models.Option import Option

        return [o for o in Option.select().where(Option.question == self)]

    def as_json(self):
        return {
            "description": self.description,
            "type": self.typ,
            "presented": self.presented,
            "options": [o.as_json() for o in self.options()],
        }


class QuestionAdmin(ModelAdmin):
    columns = ("description", "typ", "presented", "questionnaire", "id")


model_classes.append((Question, QuestionAdmin))
Exemplo n.º 18
0
from riddle import app, db, model_classes
from peewee import *
from flask_peewee.admin import ModelAdmin
import json


class Student(db.Model):
    name = CharField()
    session_id = CharField()

    def __unicode__(self):
        return self.name

    def to_json(self):
        data = {"name": self.name, "session_id": self.session_id, "id": self.id}
        return json.dumps(data)


class StudentAdmin(ModelAdmin):
    columns = ("name", "session_id")


model_classes.append((Student, StudentAdmin))
Exemplo n.º 19
0
from riddle import app, db, model_classes
from peewee import *
from flask_peewee.admin import ModelAdmin
import json


class Student(db.Model):
    name = CharField()
    session_id = CharField()

    def __unicode__(self):
        return self.name

    def to_json(self):
        data = {
            'name': self.name,
            'session_id': self.session_id,
            'id': self.id
        }
        return json.dumps(data)


class StudentAdmin(ModelAdmin):
    columns = ('name', 'session_id')


model_classes.append((Student, StudentAdmin))