Exemplo n.º 1
0
class UserMod(db.Model):
    __tablename__ = 'user_mod'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    user_id = db.Column(db.Integer, db.ForeignKey(User.id))
    type = db.Column(db.Enum(*UserModType.choices(), name='user_mod_types'))
    value = db.Column(JSON, nullable=True)
    user = db.relationship(User, backref=db.backref('usermods', lazy='joined'))
Exemplo n.º 2
0
class Role(db.Model, RoleMixin):
    __tablename__ = 'role'

    id = db.Column(db.Integer(), primary_key=True)
    name = db.Column(db.String(80), unique=True)
    description = db.Column(db.Text())
    permissions = db.Column(ARRAY(db.Text(), dimensions=1))

    def __unicode__(self):
        return self.name
Exemplo n.º 3
0
class CashFlow(db.Model):
    __tablename__ = 'cash_flow'

    id = db.Column(db.Integer, primary_key=True)
    create_at = db.Column(db.DateTime, default=datetime.datetime.now)
    name = db.Column(db.String(255))
    description = db.Column(db.String(500), nullable=True)
    amount_id = db.Column(db.Integer, db.ForeignKey(Amount.id))
    amount = db.relationship(Amount,
                             backref=db.backref('cash_flow_amounts',
                                                lazy='joined'))
Exemplo n.º 4
0
class Costs(db.Model):
    __tablename__ = 'costs'

    id = db.Column(db.Integer, primary_key=True)
    create_at = db.Column(db.DateTime, default=datetime.datetime.now)
    cash_flow_id = db.Column(db.Integer, db.ForeignKey(CashFlow.id))
    cash_flow = db.relationship(CashFlow,
                                backref=db.backref('costs_cash_flows',
                                                   lazy='joined'))
    name = db.Column(db.String(255))
    description = db.Column(db.String(500), nullable=True)
Exemplo n.º 5
0
class Bank(db.Model):
    __tablename__ = 'bank'

    id = db.Column(db.Integer, primary_key=True)
    create_at = db.Column(db.DateTime, default=datetime.datetime.now)
    name = db.Column(db.String(255))
    bank_account_id = db.Column(db.Integer, db.ForeignKey(BankAccount.id))
    bank_account = db.relationship(BankAccount,
                                   backref=db.backref('bank_bank_accounts',
                                                      lazy='joined'))
    description = db.Column(db.String(500), nullable=True)
Exemplo n.º 6
0
class UserProfile(db.Model):
    __tablename__ = 'user_profile'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    user_id = db.Column(db.Integer, db.ForeignKey(User.id))
    phone = db.Column(db.String(17))
    user = db.relationship(User,
                           backref=db.backref('user_profile_users',
                                              lazy='joined'))

    def __unicode__(self):
        return unicode(self.id)
Exemplo n.º 7
0
class ExchangeRate(db.Model):
    __tablename__ = 'exchange_rate'
    id = db.Column(db.Integer, primary_key=True)
    create_at = db.Column(db.DateTime, default=datetime.datetime.now)
    name = db.Column(db.String(255))
    date_time = db.Column(db.DateTime, default=datetime.datetime.now)
    source_id = db.Column(db.Integer, db.ForeignKey(Amount.id))
    source = db.relationship(Amount,
                             foreign_keys=source_id,
                             backref=db.backref('source_amounts',
                                                lazy='joined'))
    compare_id = db.Column(db.Integer, db.ForeignKey(Amount.id))
    compare = db.relationship(Amount,
                              foreign_keys=compare_id,
                              backref=db.backref('compare_amounts',
                                                 lazy='joined'))
    description = db.Column(db.String(500), nullable=True)
Exemplo n.º 8
0
class Amount(db.Model):
    __tablename__ = 'amount'

    id = db.Column(db.Integer, primary_key=True)
    create_at = db.Column(db.DateTime, default=datetime.datetime.now)
    value = db.Column(db.Numeric(10, 2))
    currency = db.Column(db.Enum(*AmountType.choices(), name='amount_types'),
                         default=AmountType.UAH)
    description = db.Column(db.String(500), nullable=True)
    user_id = db.Column(db.Integer, db.ForeignKey(User.id))
    user = db.relationship(User,
                           backref=db.backref('useramounts', lazy='joined'))

    def __unicode__(self):
        return u'{0} {1}'.format(self.value, self.currency)
Exemplo n.º 9
0
class Salary(db.Model):
    __tablename__ = 'salary'

    id = db.Column(db.Integer, primary_key=True)
    create_at = db.Column(db.DateTime, default=datetime.datetime.now)
    amount_id = db.Column(db.Integer, db.ForeignKey(Amount.id))
    amount = db.relationship(Amount,
                             foreign_keys=amount_id,
                             backref=db.backref('salary_amounts',
                                                lazy='joined'))
    date_time = db.Column(db.DateTime, default=datetime.datetime.now)
    exchange_rate_id = db.Column(db.Integer, db.ForeignKey(ExchangeRate.id))
    exchange_rate = db.relationship(ExchangeRate,
                                    foreign_keys=exchange_rate_id,
                                    backref=db.backref(
                                        'exchange_rate_salaries',
                                        lazy='joined'))
    description = db.Column(db.String(500), nullable=True)
Exemplo n.º 10
0
class User(db.Model, UserMixin):
    __tablename__ = 'auth_user'

    id = db.Column(db.Integer, primary_key=True)
    email = db.Column(db.String(255), nullable=False, unique=True)
    password = db.Column(db.String(255))
    active = db.Column('is_active', db.Boolean(), nullable=False, default=True)
    username = db.Column(db.String(128), nullable=False, default=' ')
    first_name = db.Column(db.String(30), nullable=False, default=' ')
    last_name = db.Column(db.String(30), nullable=False, default=' ')
    is_staff = db.Column(db.Boolean(), nullable=False, default=False)
    is_superuser = db.Column(db.Boolean(), nullable=False, default=False)
    last_login = db.Column(db.DateTime,
                           nullable=False,
                           default=datetime.datetime.now)
    date_joined = db.Column(db.DateTime,
                            nullable=False,
                            default=datetime.datetime.now)
    roles = db.relationship(Role,
                            secondary=roles_users,
                            backref=db.backref('users'))

    def __unicode__(self):
        return u'{0} {1}'.format(self.id, self.email)

    def has_any_perm(self, *perms):
        has = set(
            itertools.chain.from_iterable(role.permissions
                                          for role in self.roles))
        return self.is_superuser or has.intersection(perms)
Exemplo n.º 11
0
    auth.models
    ~~~~~~~~~~~
"""

import itertools
import datetime

from sqlalchemy.dialects.postgresql import ARRAY, JSON
from flask.ext.security import UserMixin, RoleMixin, current_user
from flask_security.utils import encrypt_password

from budgetfamily import db

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


class Role(db.Model, RoleMixin):
    __tablename__ = 'role'

    id = db.Column(db.Integer(), primary_key=True)
    name = db.Column(db.String(80), unique=True)
    description = db.Column(db.Text())
    permissions = db.Column(ARRAY(db.Text(), dimensions=1))

    def __unicode__(self):
        return self.name