Exemple #1
0
class Profile(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    user = db.relationship('User',
                           primaryjoin='foreign(Profile.user_id) == User.id',
                           uselist=False,
                           cascade=False,
                           lazy='joined',
                           backref=db.backref('profile',
                                              uselist=False,
                                              lazy='joined'))

    admin = db.Column(db.Boolean, default=False)
    primary_chapter_id = db.Column(db.Integer, nullable=True)
    primary_chapter = db.relationship(
        'Chapter',
        primaryjoin='foreign(Profile.primary_chapter_id) == Chapter.id',
        uselist=False,
        cascade=False,
        lazy='joined')

    def is_active(self):
        return self.user.is_active()

    def is_admin(self):
        return self.admin
Exemple #2
0
class WLWMixin(object):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(255), nullable=False)
    description = db.Column(db.Text, nullable=True)
    active = db.Column(db.Boolean, default=False)
    removed = db.Column(db.Boolean, default=False)
    admin = db.Column(db.Boolean, default=False)
    created_on = db.Column(db.DateTime(timezone=True),
            default=db.func.now())
    updated_on = db.Column(db.DateTime(timezone=True),
            default=db.func.now(),
            onupdate=db.func.now())

    @declared_attr
    def __tablename__(cls):
        return cls.__name__.lower()

    def is_expired(self):
        return self.expired

    def is_hidden(self):
        return self.hidden

    def is_admin(self):
        return self.admin

    def __str__(self):
        return self.name

    def __repr__(self):
        return "<%s: %s>" % (self.__class__.__name__, str(self))
Exemple #3
0
class Character(db.Model, mixins.WLWMixin):
    private_description = db.Column(db.Text, nullable=True)
    chapter_id = db.Column(db.Integer, db.ForeignKey('chapter.id'), nullable=False)
    chapter = db.relationship('Chapter',
            primaryjoin="Character.chapter_id == Chapter.id",
            uselist=False,
            cascade=False,
            backref=db.backref('characters', uselist=True))
    owner_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=True)
    owner = db.relationship('User',
            primaryjoin="Character.owner_id == User.id",
            # TODO - re-evaluate for multi-owner characters; for example, NPCs.
            uselist=False,
            cascade=False,
            backref=db.backref('characters', uselist=True))
Exemple #4
0
class Chapter(db.Model, mixins.WLWMixin):
    venue_id = db.Column(db.Integer, db.ForeignKey('venue.id'), nullable=False)
    venue = db.relationship('Venue',
            primaryjoin="Chapter.venue_id == Venue.id",
            uselist=False,
            cascade=False,
            backref=db.backref('chapters', uselist=True, cascade="all, delete-orphan"))
Exemple #5
0
class Role(db.Model, RoleMixin):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(80), unique=True, nullable=False)
    description = db.Column(db.String(255))
    chapter_id = db.Column(db.Integer,
                           db.ForeignKey('chapter.id'),
                           nullable=True)
    venue_id = db.Column(db.Integer, db.ForeignKey('venue.id'), nullable=True)
    chapter = db.relationship(
        'Chapter',
        primaryjoin='foreign(Role.chapter_id) == Chapter.id',
        uselist=False,
        cascade=False,
        backref=db.backref('roles', uselist=True, order_by=id))
    venue = db.relationship('Venue',
                            primaryjoin='foreign(Role.venue_id) == Venue.id',
                            uselist=False,
                            cascade=False,
                            backref=db.backref('roles',
                                               uselist=True,
                                               order_by=id))
    created_on = db.Column(db.DateTime, default=db.func.now())
    updated_on = db.Column(db.DateTime, default=db.func.now())

    def __eq__(self, other):
        return ((self.name == other.name and self.chapter == other.chapter)
                or (self.name == getattr(other, 'name', None)
                    and self.chapter == getattr(other, 'chapter', None)))

    def __str__(self):
        return self.name

    def __repr__(self):
        return u'<Role: %s (%s, %s)>' % (self.name, self.venue, self.chapter)
Exemple #6
0
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    password = db.Column(db.String)
    email = db.Column(db.String, unique=True)
    active = db.Column(db.Boolean, default=False)
    # flask.ext.security required
    confirmed_at = db.Column(db.DateTime)
    # end flask.ext.security
    created_on = db.Column(db.DateTime(timezone=True), default=db.func.now())
    updated_on = db.Column(db.DateTime(timezone=True),
                           default=db.func.now(),
                           onupdate=db.func.now())
    roles = db.relationship('Role',
                            secondary=roles_users,
                            backref=db.backref('users', lazy='dynamic'))
    anonymous = True
    authenticated = False

    def is_active(self):
        return self.active

    def is_admin(self):
        # TODO - make this check the profile
        return True

    password_updated = willow_signals.signal('user-updated-password')
    new_user = willow_signals.signal('user-new')
    deletion = willow_signals.signal('user-deletion')
    login_success = willow_signals.signal('user-login-success')
    login_fail = willow_signals.signal('user-login-fail')
Exemple #7
0
class GenericTrait(db.Model, mixins.TraitMixin):
    """
    Example GenericTrait.
    TraitMixin should be used as a base for any Mixins created
    for custom traits and trait types.
    """
    base_cost = 2
    type_id = db.Column(db.Integer, db.ForeignKey('traittype.id'), nullable=False)
    type = db.relationship('TraitType',
            primaryjoin="GenericTrait.type_id == TraitType.id",
            uselist=False,
            cascade=False,
            backref=db.backref('generic_traits', uselist=True))
Exemple #8
0
class TraitMixin(WLWMixin):
    # Override name
    name = db.Column(db.String(255), unique=True, nullable=False)

    base_cost = 1
    modifiers = []

    def calculate_cost(self,multiplier=None,modifiers=None):
        if not multiplier:
            multiplier = 1
        if not modifiers:
            modifiers = self.modifiers

        cost = self.base_cost * multiplier
        cost += sum([int(mod) for mod in modifiers])

        return cost
Exemple #9
0
from passlib.hash import bcrypt
from flask import current_app, flash, abort
from flask_security.core import current_user
from willow.app import willow_signals
from willow.models import db
from flask.ext.security import RoleMixin, UserMixin

roles_users = db.Table(
    'roles_users', db.Column('user_id', db.Integer(),
                             db.ForeignKey('user.id')),
    db.Column('role_id', db.Integer(), db.ForeignKey('role.id')))


class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    password = db.Column(db.String)
    email = db.Column(db.String, unique=True)
    active = db.Column(db.Boolean, default=False)
    # flask.ext.security required
    confirmed_at = db.Column(db.DateTime)
    # end flask.ext.security
    created_on = db.Column(db.DateTime(timezone=True), default=db.func.now())
    updated_on = db.Column(db.DateTime(timezone=True),
                           default=db.func.now(),
                           onupdate=db.func.now())
    roles = db.relationship('Role',
                            secondary=roles_users,
                            backref=db.backref('users', lazy='dynamic'))
    anonymous = True
    authenticated = False