Esempio n. 1
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)
Esempio n. 2
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))
Esempio n. 3
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
Esempio n. 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"))
Esempio n. 5
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))
Esempio n. 6
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