class Task(TimestampMixin, db.Model): __tablename__ = 'task' id = db.Column(db.BigInteger, primary_key=True) type = db.Column(db.String, nullable=False) task_id = db.Column(db.String(155), unique=False) status = db.Column(db.String(50), nullable=True) user_id = db.Column(db.BigInteger, db.ForeignKey(User.id), nullable=True) result = db.Column(db.LargeBinary, nullable=True) target_type = db.Column(db.String, nullable=True) target_id = db.Column(db.BigInteger, nullable=True) def __repr__(self): return "<Task(id='%r', task_id='%r', user_id='%r', status='%r')>" % ( self.id, self.task_id, self.user_id, self.status)
class Configuration(TimestampMixin, db.Model): __tablename__ = 'configuration' key = db.Column(db.String(128), primary_key=True) description = db.Column(db.String, nullable=True) value = db.Column(db.String, nullable=True) def __repr__(self): return "<Configuration(key='%r', value='%r')>" % (self.key, self.value)
class EnrollmentModel(TimestampMixin, db.Model): __tablename__ = 'enrollment_model' tesla_id = db.Column(db.String(64), db.ForeignKey(Learner.tesla_id), primary_key=True) instrument_id = db.Column(db.BigInteger, db.ForeignKey(Instrument.id), primary_key=True) status = db.Column(db.Integer, nullable=False, default=0) locked = db.Column(db.Boolean, nullable=False, default=False) lock_date = db.Column(db.DateTime, nullable=True) lock_code = db.Column(db.String(64), nullable=True) data = db.Column(db.LargeBinary, nullable=True) def __repr__(self): return "<EnrollmentModel(tesla_id='%s', instrument_id='%d', status='%d', locked='%r')>" % ( self.tesla_id, self.instrument_id, self.status, self.locked)
class User(db.Model, UserMixin): __tablename__ = 'user' id = db.Column(db.Integer, primary_key=True) email = db.Column(db.String(255), unique=True) username = db.Column(db.String(255), unique=True) password = db.Column(db.String(255)) last_login_at = db.Column(db.DateTime()) current_login_at = db.Column(db.DateTime()) last_login_ip = db.Column(db.String(100)) locale = db.Column(db.String(10), default='en_GB') timezone = db.Column(db.String(15), default='UTC') current_login_ip = db.Column(db.String(100)) login_count = db.Column(db.Integer) active = db.Column(db.Boolean()) confirmed_at = db.Column(db.DateTime()) roles = db.relationship('Role', secondary='roles_users', backref=db.backref('users', lazy='dynamic')) def check_password(self, password): return verify_password(password, self.password) # Custom User Payload def get_security_payload(self): return { 'id': self.id, 'username': self.username, 'email': self.email, 'locale': self.locale, 'timezone': self.timezone }
class CourseLearner(db.Model): __tablename__ = 'course_learner' course_id = db.Column(db.BigInteger, db.ForeignKey(Course.id), primary_key=True) tesla_id = db.Column(db.String(64), db.ForeignKey(Learner.tesla_id), primary_key=True) def __repr__(self): return "<Course(id='%r', code='%s')>" % (self.id, self.code)
class InformedConsentDocument(TimestampMixin, db.Model): __tablename__ = 'informed_consent_document' consent_id = db.Column(db.BigInteger, db.ForeignKey(InformedConsent.id), primary_key=True) language = db.Column(db.String(10), primary_key=True) html = db.Column(db.String, nullable=True) pdf = db.Column(db.LargeBinary, nullable=True) def __repr__(self): return "<InformedConsentDocument(consent_id='%d', language='%s')>" % ( self.consent_id, self.language)
class LearnerSEND(TimestampMixin, db.Model): __tablename__ = 'learner_send' tesla_id = db.Column(db.String(64), db.ForeignKey(Learner.tesla_id), primary_key=True) category_id = db.Column(db.BigInteger, db.ForeignKey(SENDCategory.id), primary_key=True) expires = db.Column(db.DateTime, nullable=True) def __repr__(self): return "<LearnerSEND(tesla_id='%r', category_id='%d')>" % ( self.tesla_id, self.category_id)
class Learner(TimestampMixin, db.Model): __tablename__ = 'learner' tesla_id = db.Column(db.String(64), nullable=False, primary_key=True) crypto_data = db.Column(db.LargeBinary, nullable=True) consent_id = db.Column(db.BigInteger, db.ForeignKey(InformedConsent.id), nullable=True) consent_accepted = db.Column(db.DateTime, nullable=True) consent_rejected = db.Column(db.DateTime, nullable=True) def __repr__(self): return "<Learner(tesla_id='%r', consent_id='%r')>" % (self.tesla_id, self.consent_id)
class InstrumentThresholds(TimestampMixin, db.Model): __tablename__ = 'instrument_thresholds' instrument_id = db.Column(db.BigInteger, db.ForeignKey(Instrument.id), primary_key=True) low = db.Column(db.Float, nullable=False) medium = db.Column(db.Float, nullable=False) high = db.Column(db.Float, nullable=False) audit_level = db.Column(db.String(6), nullable=False) def __repr__(self): return "<InstrumentThresholds(instrument_id='%r', low='%r', medium='%r', high='%r', audit_level='%r')>" % ( self.instrument_id, self.low, self.medium, self.high, self.audit_level)
class Enrollment(TimestampMixin, db.Model): __tablename__ = 'enrollment' tesla_id = db.Column(db.String(64), db.ForeignKey(Learner.tesla_id), primary_key=True) instrument_id = db.Column(db.BigInteger, db.ForeignKey(Instrument.id), primary_key=True) percentage = db.Column(db.Numeric, nullable=False, default=0.0) status = db.Column(db.Integer, nullable=False, default=0) def __repr__(self): return "<Enrollment(tesla_id='%s', instrument_id='%d', status='%r', percentage='%r')>" % ( self.tesla_id, self.instrument_id, self.status, self.percentage)
class Request(TimestampMixin, db.Model, TimestampStartEndMixin): __tablename__ = 'request' id = db.Column(db.BigInteger, primary_key=True) tesla_id = db.Column(db.String(64), db.ForeignKey(Learner.tesla_id), nullable=False) status = db.Column(db.Integer, nullable=False, default=0) activity_id = db.Column(db.BigInteger, db.ForeignKey(Activity.id), nullable=True) is_enrolment = db.Column(db.Boolean, nullable=True) instrument_list = db.Column(db.String, nullable=False) def __repr__(self): return "<Request(id='%r', tesla_id='%s', activity_id='%r', status='%r', is_enrollment='%r')>" % ( self.id, self.tesla_id, self.activity_id, self.status, self.is_enrolment)
class Role(db.Model, RoleMixin): __tablename__ = 'role' id = db.Column(db.Integer(), primary_key=True) name = db.Column(db.String(80), unique=True) description = db.Column(db.String(255))