Ejemplo n.º 1
0
class Result(db.Model):

    __tablename__ = 'results'

    id = db.Column(db.Integer, primary_key=True)
    topicID = db.Column(
        db.Integer,
        db.ForeignKey('topics.id', onupdate='CASCADE', ondelete='CASCADE'))
    accountID = db.Column(
        db.Integer,
        db.ForeignKey('users.id', onupdate='CASCADE', ondelete='CASCADE'))
    date = db.Column(db.DateTime, nullable=False)
    percentage = db.Column(db.String(3), nullable=False)

    def __init__(self, topicID, accountID, percentage):
        self.topicID = topicID
        self.accountID = accountID
        self.date = datetime.utcnow()
        self.percentage = percentage

    def serialize(self):
        return {
            'id': self.id,
            'userID': self.accountID,
            'date': str(self.date),
            'percentage': self.percentage,
        }
Ejemplo n.º 2
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()
Ejemplo n.º 3
0
class Follow(db.Model):

    __tablename__ = 'follow'

    id = db.Column(db.Integer, primary_key=True)
    follower = db.Column(
        db.Integer,
        db.ForeignKey('users.id', onupdate='CASCADE', ondelete='CASCADE'))
    following = db.Column(
        db.Integer,
        db.ForeignKey('users.id', onupdate='CASCADE', ondelete='CASCADE'))

    def __init__(self, follower, following):
        self.follower = follower
        self.following = following

    def serialize(self):
        return {
            'id': self.id,
            'follower': self.follower,
            'following': self.following,
        }
Ejemplo n.º 4
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()
Ejemplo n.º 5
0
class Warning(db.Model):

    __tablename__ = 'warnings'

    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)
    date = db.Column(db.DateTime, nullable=False)

    def __init__(self, userID, issue):
        self.userID = userID
        self.issue = issue
        self.date = datetime.utcnow()
Ejemplo n.º 6
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,
        }
Ejemplo n.º 7
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),
        }
Ejemplo n.º 8
0
class Question(db.Model):

    __tablename__ = 'questions'

    id = db.Column(db.Integer, primary_key=True)
    topicID = db.Column(
        db.Integer,
        db.ForeignKey('topics.id', onupdate='CASCADE', ondelete='CASCADE'))
    question = db.Column(db.String(8000), nullable=False)
    answer = db.Column(db.String(8000))

    def __init__(self, topicID, question, answer):
        self.topicID = topicID
        self.question = question
        self.answer = answer

    def serialize(self):
        return {
            'id': self.id,
            'title': self.question,
            'answer': self.answer if self.answer != "" else None
        }
Ejemplo n.º 9
0
class OAuth(db.Model):

    __tablename__ = 'oauth'

    id = db.Column(db.Integer, primary_key=True)
    userID = db.Column(db.Integer,
                       db.ForeignKey('users.id',
                                     onupdate='CASCADE',
                                     ondelete='CASCADE'),
                       nullable=False)
    socialID = db.Column(db.String(64), nullable=False)
    provider = db.Column(db.String(1), nullable=False)
    accessToken = db.Column(db.Text, nullable=False)
    name = db.Column(db.Text, nullable=False)

    def __init__(self, userID, socialID, provider, accessToken, name):
        self.userID = userID
        self.socialID = socialID
        self.provider = provider
        self.accessToken = accessToken
        self.name = name

    @hybrid_property
    def url(self):
        if self.provider == 'G':
            return 'https://plus.google.com/' + str(self.socialID)
        elif self.provider == 'F':
            return 'https://facebook.com/' + str(self.socialID)

    def serialize(self):
        return {
            'id': self.id,
            'userID': self.userID,
            'socialID': self.socialID,
            'provider': self.provider,
            'accessToken': self.accessToken,
            'name': self.name
        }
Ejemplo n.º 10
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(),
        }