Example #1
0
class User(UserMixin, SurrogatePK, Model):
    """A user of the app."""

    __tablename__ = "users"
    username = Column(db.String(80), unique=True, nullable=False)
    email = Column(db.String(80), unique=True, nullable=False)
    #: The hashed password
    password = Column(db.LargeBinary(128), nullable=True)
    created_at = Column(db.DateTime, nullable=False, default=dt.datetime.utcnow)
    active = Column(db.Boolean(), default=False)
    is_admin = Column(db.Boolean(), default=False)
    is_instructor = Column(db.Boolean(), default=False)
    is_static = Column(db.Boolean(), default=False) # static: user belongs to one group only (for generated groups)

    def __init__(self, username, email, password=None, **kwargs):
        """Create instance."""
        db.Model.__init__(self, username=username, email=email, **kwargs)
        if password:
            self.set_password(password)
        else:
            self.password = None

    def set_password(self, password):
        """Set password."""
        self.password = bcrypt.generate_password_hash(password)

    def check_password(self, value):
        """Check password."""
        return bcrypt.check_password_hash(self.password, value)

    def __repr__(self):
        """Represent instance as a unique string."""
        return f"<User({self.username!r})>"
Example #2
0
class StudentGroups(UserMixin, SurrogatePK, Model):
    """"Groupts of Users"""
    __tablename__ = "groups"
    name = Column(db.String(40), unique=True, nullable=False)
    owner_id = reference_col("users", nullable=False)
    owner = relationship("User", backref="groups")
    code = Column(db.String(8),
                  unique=True,
                  nullable=True,
                  default=generate_registration_code())
    hidden = Column(db.Boolean(), nullable=False, default=False)
Example #3
0
class Responses(UserMixin, SurrogatePK, Model):
    """Student responses to scenario questions"""

    __tablename__ = "responses"
    user_id = reference_col("users", nullable=False)
    user = relationship("User", backref="responses")
    scenario_id = reference_col("scenarios", nullable=False)
    scenario = relationship("Scenarios", backref="responses")
    question = Column(db.Integer, default=0, nullable=False)
    student_response = Column(db.String(40), unique=False, nullable=True)
    correct = Column(db.Boolean(), default=False)
    response_time = Column(db.DateTime,
                           nullable=False,
                           default=dt.datetime.utcnow)
    attempt = Column(db.Integer, default=0, nullable=False)