Exemple #1
0
class Report(db.Model):

    __tablename__ = 'reports'

    id = db.Column(db.Integer, primary_key=True)
    userID = db.Column(
        db.Integer,
        db.ForeignKey('users.id', onupdate='CASCADE', ondelete='CASCADE'))
    issue = db.Column(db.Text(100), nullable=False)
    userReportedID = db.Column(
        db.Integer,
        db.ForeignKey('users.id', onupdate='CASCADE', ondelete='CASCADE'))
    date = db.Column(db.DateTime, nullable=False)
    user = db.relationship('User', foreign_keys=[userID])
    userReported = db.relationship('User', foreign_keys=[userReportedID])

    def __init__(self, userID, userReportedID, issue):
        self.userID = userID
        self.userReportedID = userReportedID
        self.issue = issue
        self.date = datetime.utcnow()
Exemple #2
0
class Subject(db.Model):

    __tablename__ = 'subjects'

    id = db.Column(db.Integer, primary_key=True)
    hash = db.Column(db.String(6))
    accountID = db.Column(
        db.Integer,
        db.ForeignKey('users.id', onupdate="CASCADE", ondelete="CASCADE"))
    name = db.Column(db.String(100), nullable=False, index=True)
    slug = db.Column(db.String(200), nullable=False)
    color = db.Column(db.Integer, nullable=False)
    date = db.Column(db.DateTime, nullable=False)
    topic = db.relationship('Topic', backref=backref('subject'))
    user = db.relationship('User')

    def __init__(self, accountID, name, color):
        self.accountID = accountID
        self.name = name
        self.color = color
        self.slug = utils.subjectSlug(name)
        self.date = datetime.utcnow()

    @property
    def shareLink(self):
        string = 's' + self.hash
        return url_for('social.share', string=string, _external=True)

    @property
    def colors(self):
        return utils.getColorByNumber(self.color)

    def serialize(self):
        return {
            'id': self.id,
            'name': self.name,
            'userID': self.accountID,
            'color': self.color,
            'date': str(self.date),
        }
Exemple #3
0
class Ban(db.Model):

    __tablename__ = 'banned'

    id = db.Column(db.Integer, primary_key=True)
    userID = db.Column(
        db.Integer,
        db.ForeignKey('users.id', onupdate="CASCADE", ondelete="CASCADE"))
    date = db.Column(db.DateTime, nullable=False)
    user = db.relationship('User', backref=backref('banned'))

    def __init__(self, userID):
        self.userID = userID
        self.date = datetime.utcnow()
Exemple #4
0
class Topic(db.Model):

    __tablename__ = 'topics'

    id = db.Column(db.Integer, primary_key=True)
    hash = db.Column(db.String(6))
    subjectID = db.Column(
        db.Integer,
        db.ForeignKey('subjects.id', onupdate='CASCADE', ondelete='CASCADE'))
    name = db.Column(db.String(150), nullable=False, index=True)
    slug = db.Column(db.String(200), nullable=False)
    questions = db.relationship('Question', backref=backref('topic'))
    date = db.Column(db.DateTime, nullable=False)

    def __init__(self, subjectID, name):
        self.subjectID = session['newTopicSubjectID'] = subjectID
        self.name = name
        self.slug = utils.topicSlug(name)
        self.date = datetime.utcnow()

    @property
    def shareLink(self):
        string = 't' + self.hash
        return url_for('social.share', string=string, _external=True)

    @property
    def colors(self):
        return self.subject.colors

    @property
    def user(self):
        return self.subject.user

    def serialize(self):
        return {
            'id': self.id,
            'name': self.name,
            'date': str(self.date),
            'subjectID': self.subjectID,
        }
Exemple #5
0
class WeeklyGoal(db.Model):

    __tablename__ = 'weekly_goal'

    id = db.Column(db.Integer, primary_key=True)
    userID = db.Column(
        db.Integer,
        db.ForeignKey('users.id', onupdate='CASCADE', ondelete='CASCADE'))
    progress = db.Column(db.Integer, nullable=False)
    date = db.Column(db.Date, nullable=False)
    user = db.relationship('User', backref=backref('goal'))

    def __init__(self, progress):
        self.userID = current_user.id
        self.progress = progress
        self.date = datetime.today() - timedelta(
            days=datetime.today().isoweekday() % 7)

    @property
    def total(self):
        return self.user.weeklyGoal

    def completed(self):
        if self.progress >= self.user.weeklyGoal:
            return True
        else:
            return False

    def serialize(self):
        return {
            'id': self.id,
            'userID': self.userID,
            'progress': self.progress,
            'date': str(self.date),
            'user': self.user.serialize(),
        }