Esempio n. 1
0
class UserKey(db.Model):
    #SQL table defines
    id = db.Column(db.Integer, primary_key=True)
    key = db.Column(db.String(80), unique=True)

    #Row initalization
    def __init__(self):
        self.key = str(uuid.uuid4())[:8]

    #Basically toString()
    def __repr__(self):
        return '<UserKey %r>' % self.key
Esempio n. 2
0
class Vote(db.Model):
    """Table model for 
    """
    #SQL table defines
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(255))
    start_time = db.Column(db.DateTime)
    end_time = db.Column(db.DateTime)
    description = db.Column(db.Text, default="Description here")
    results = db.Column(db.PickleType(comparator=lambda *a: False))
    form = db.Column(db.PickleType())
    time = db.Column(db.DateTime)

    #Checks times
    def is_locked(self):
        return self.results != [] or self.is_active()

    def is_active(self):
        return self.start_time < datetime.datetime.utcnow() < self.end_time

    #Row initialization
    def __init__(self, title):
        self.title = title[0].upper() + title[1:]
        self.time = datetime.datetime.utcnow()
        self.start_time = (datetime.datetime.utcnow() -
                           datetime.timedelta(seconds=1))
        self.end_time = (datetime.datetime.utcnow())
        self.results = []

    #Basically toString()
    def __repr__(self):
        return '<Vote %r>' % self.title
Esempio n. 3
0
class News(db.Model):
    """Table model for 
    """
    #SQL table defines
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(255))
    body = db.Column(db.Text)
    time = db.Column(db.DateTime, default=datetime.datetime.utcnow())

    #Row initialization
    def __init__(self, title):
        self.title = title[0].upper() + title[1:]

    #Basically toString()
    def __repr__(self):
        return '<News %r>' % self.title
Esempio n. 4
0
class User(db.Model):
    #SQL table defines
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(80), unique=True)
    pw_hash = db.Column(db.String(80))
    grade = db.Column(db.Integer)
    admin = db.Column(db.Boolean)
    votes = db.relationship('Vote',
                            secondary=votes,
                            backref=db.backref('users', lazy='joined'),
                            lazy='dynamic')

    #If user is authenticated
    def is_authenticated(self):
        return True

    #If user is active
    def is_active(self):
        return True

    #If user is anonymous
    def is_anonymous(self):
        return False

    #If user is admin
    def is_admin(self):
        return self.admin

    #Gets user id
    def get_id(self):
        return unicode(self.id)

    #Hashes user password
    def set_password(self, password):
        self.pw_hash = generate_password_hash(password)

    #Checks if user password matches hashed password
    def check_password(self, password):
        return check_password_hash(self.pw_hash, password)

    #Basically toString()
    def __repr__(self):
        return '<User %r>' % self.username
Esempio n. 5
0
#This file defines the models for the voting tables

#Misc imports
import time
import datetime
#PVS imports
from pvs import app, db

#Relationship table for users and votes
votes = db.Table('votes',
                 db.Column('user_id', db.Integer, db.ForeignKey('user.id')),
                 db.Column('vote_id', db.Integer, db.ForeignKey('vote.id')),
                 sqlite_autoincrement=True)


#Model for votes
class Vote(db.Model):
    """Table model for 
    """
    #SQL table defines
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(255))
    start_time = db.Column(db.DateTime)
    end_time = db.Column(db.DateTime)
    description = db.Column(db.Text, default="Description here")
    results = db.Column(db.PickleType(comparator=lambda *a: False))
    form = db.Column(db.PickleType())
    time = db.Column(db.DateTime)

    #Checks times
    def is_locked(self):