예제 #1
0
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    firstname = db.Column(db.String(20), nullable=False)
    lastname = db.Column(db.String(20), nullable=False)
    email = db.Column(db.String(120), unique=True, nullable=False)
    gender = db.Column(db.String(5), nullable=False)
    password = db.Column(db.String(60), nullable=False)
    is_admin = db.Column(db.Boolean, default=False)
    response = db.relationship('Response', backref='user', lazy=True)

    def get_reset_token(self, expires_sec=1800):
        s = Serializer(current_app.config['SECRET_KEY'], expires_sec)
        return s.dumps({'user_id': self.id}).decode('utf-8')

    @staticmethod
    def verify_reset_token(token):
        s = Serializer(current_app.config['SECRET_KEY'])
        try:
            user_id = s.loads(token)['user_id']
        except:
            return None
        return User.query.get(user_id)

    def __repr__(self):
        return f"User('{self.firstname}', '{self.lastname}','{self.gender}', '{self.email}')"
예제 #2
0
class Category(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(50), nullable=False)
    response = db.relationship('Response', backref='category', lazy=True)
    poll = db.relationship('Poll', backref='category', lazy=True)
    image_file = db.Column(db.String(20),
                           nullable=False,
                           default='default.jpg')
    description = db.Column(
        db.String(500),
        nullable=False,
        default='There is currrentlly no information. Please wait for update')
    end_date = db.Column(db.DateTime, nullable=False)

    def __repr__(self):
        return f"Category('{self.name}')"
class Question(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    question_text = db.Column(db.String(200))
    number_of_yes_votes = db.Column(db.Integer, default=0)
    number_of_no_votes = db.Column(db.Integer, default=0)
    number_of_maybe_votes = db.Column(db.Integer, default=0) 

    def __init__(self, 
                 question_text,
                 number_of_yes_votes=0,
                 number_of_no_votes=0,
                 number_of_maybe_votes=0):

        self.question_text = question_text
        self.number_of_yes_votes = number_of_yes_votes
        self.number_of_no_votes = number_of_no_votes
        self.number_of_maybe_votes = number_of_maybe_votes


    def vote(self, vote_type):
        if vote_type == 'yes': 
            self.number_of_yes_votes += 1
        elif vote_type == 'no':
            self.number_of_no_votes += 1
        elif vote_type == 'maybe': 
            self.number_of_maybe_votes += 1
        else: 
            raise Exception("Invalid vote type")
예제 #4
0
class Poll(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(50), nullable=False)
    rank = db.Column(db.Integer, nullable=False)
    category_id = db.Column(db.Integer,
                            db.ForeignKey('category.id'),
                            nullable=False)
    response = db.relationship('Response', backref='poll', lazy=True)
    image_file = db.Column(db.String(20),
                           nullable=False,
                           default='default.jpg')
    video_url = db.Column(db.String(200),
                          nullable=False,
                          default="https://www.youtube.com/embed/m_NeIyG98Nc")
    description = db.Column(
        db.String(500),
        nullable=False,
        default='Get more information by clicking the play button!!!')

    def __repr__(self):
        return f"Poll('{self.name}', '{self.rank}')"
예제 #5
0
class Question(db.Model):
    def __init__(self, question_text, nu_yes=0, nu_no=0, nu_maybe=0):
        self.text = question_text
        self.nu_maybe = nu_maybe
        self.nu_no = nu_no
        self.nu_yes = nu_yes

    # Flask - ORM
    id = db.Column(db.Integer, primary_key=True)
    text = db.Column(db.String(40))
    nu_yes = db.Column(db.Integer, default=0)
    nu_no = db.Column(db.Integer, default=0)
    nu_maybe = db.Column(db.Integer, default=0)

    def vote(self, votetpe):
        if votetpe == 'yes':
            self.nu_yes += 1
        elif votetpe == 'no':
            self.nu_no += 1
        elif votetpe == 'maybe':
            self.nu_maybe += 1
        else:
            raise Exception('Invalid vote')
예제 #6
0
class Question(db.Model):
    """ A model for 'Question' """
    id = db.Column(db.Integer, primary_key=True)
    question_text = db.Column(db.String(200))
    number_of_yes_votes = db.Column(db.Integer, default=0)
    number_of_no_votes = db.Column(db.Integer, default=0)
    number_of_maybe_votes = db.Column(db.Integer, default=0)

    def __init__(self,
                 question_text,
                 pub_date=None,
                 number_of_yes_votes=0,
                 number_of_no_votes=0,
                 number_of_maybe_votes=0):

        self.question_text = question_text

        if pub_date is None:
            pub_date = datetime.utcnow()
        self.pub_date = pub_date

        self.number_of_yes_votes = number_of_yes_votes
        self.number_of_maybe_votes = number_of_maybe_votes
        self.number_of_no_votes = number_of_no_votes

    def __repr__(self):
        return '<Question %d - %r>' % (self.id, self.question_text)

    def vote(self, vote_type):
        if vote_type == 'yes':
            self.number_of_yes_votes += 1
        elif vote_type == 'no':
            self.number_of_no_votes += 1
        elif vote_type == 'maybe':
            self.number_of_maybe_votes += 1
        else:
            raise Exception