コード例 #1
0
ファイル: models.py プロジェクト: gseastream/kudos
class Award(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(64), nullable=False)
    nominations = db.relationship("Nomination", backref="award")
    order = db.Column(db.Integer, nullable=False, default=1000)

    def __repr__(self):
        return "<Award %r>" % self.name
コード例 #2
0
ファイル: models.py プロジェクト: gseastream/kudos
class State(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    # 0 is static, 1 is nominations, 2 is voting
    phase = db.Column(db.Integer, nullable=False)
    dtnom = db.Column(db.DateTime)
    dtvote = db.Column(db.DateTime)
    dtstatic = db.Column(db.DateTime)

    def __repr__(self):
        return "<State %r>" % self.id
コード例 #3
0
ファイル: models.py プロジェクト: gseastream/kudos
class Nomination(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(128), nullable=False)
    award_id = db.Column(db.Integer, db.ForeignKey("award.id"), nullable=False)
    creator = db.relationship("User", backref="entries")
    creator_id = db.Column(db.Integer, db.ForeignKey("user.id"), nullable=False)
    voters = db.relationship("User", secondary=users,
                             backref=db.backref("selections"))

    @property
    def votes(self):
        return len(self.voters)

    def __repr__(self):
        return "<Nomination %r>" % self.id
コード例 #4
0
class Stats(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    distance = db.Column(db.Float, nullable=False)
    distance1 = db.Column(db.Float, nullable=False)
    distance2 = db.Column(db.Float, nullable=False)
    cash = db.Column(db.Float, nullable=False)
    venmo = db.Column(db.Float, nullable=False)
    card = db.Column(db.Float, nullable=False)
    misc = db.Column(db.Float, nullable=False)
    start_venmo_bal = db.Column(db.Float, nullable=False)

    def __repr__(self):
        return '<Stats %r>' % self.id
コード例 #5
0
ファイル: models.py プロジェクト: gseastream/kudos
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(16), unique=True, nullable=False)
    _password = db.Column(db.String(128), nullable=False,
                          default=default_password)
    email = db.Column(db.String(128), nullable=False, default=default_email)
    email_confirmed = db.Column(db.Boolean, default=False, nullable=False)
    sessTokenTime = db.Column(db.Float, nullable=False, default=time.time)
    banned = db.Column(db.Boolean, default=False, nullable=False)
    is_admin = db.Column(db.Boolean, default=False, nullable=False)

    @hybrid_property
    def password(self):
        return self._password

    @password.setter
    def password(self, plaintext):
        self._password = \
            bcrypt.generate_password_hash(plaintext).decode("utf-8")
        self.reset_token() # reset the token when you change the password

    def is_correct_password(self, plaintext):
        return bcrypt.check_password_hash(self._password, plaintext)

    def reset_token(self):
        self.sessTokenTime = time.time()

    def ban(self):
        self.banned = True
        self.reset_token() # invalidate their sessions

    def unban(self):
        self.banned = False

    def give_admin(self):
        self.is_admin = True

    def take_admin(self):
        self.is_admin = False

    # Flask-Login properties
    @property
    def is_authenticated(self):
        return True

    @property
    def is_active(self):
        return not self.banned and self.email_confirmed

    def get_id(self):
        return serializer.dumps([self.id, self.sessTokenTime], salt="session")

    def __repr__(self):
        return "<User %r>" % self.username
コード例 #6
0
ファイル: models.py プロジェクト: gseastream/kudos
from sqlalchemy.ext.hybrid import hybrid_property
from flask_login import UserMixin
import time
from app_manager import db, bcrypt, serializer

users = db.Table("users",
    db.Column("user_id", db.Integer, db.ForeignKey("user.id"),
              primary_key=True),
    db.Column("nom_id", db.Integer, db.ForeignKey("nomination.id"),
              primary_key=True)
)

def default_email(context):
    # Andrew email should be used, but it could be different
    if context is None:
        # flask_admin's create interface will pass None for context
        return "*****@*****.**"
    return context.get_current_parameters()["username"] + "@andrew.cmu.edu"

def default_password():
    # decode string to avoid invalid salt error with postgres
    return bcrypt.generate_password_hash("password").decode("utf-8")

class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(16), unique=True, nullable=False)
    _password = db.Column(db.String(128), nullable=False,
                          default=default_password)
    email = db.Column(db.String(128), nullable=False, default=default_email)
    email_confirmed = db.Column(db.Boolean, default=False, nullable=False)
    sessTokenTime = db.Column(db.Float, nullable=False, default=time.time)