コード例 #1
0
ファイル: ledger.py プロジェクト: pooldin/pooldlib
class ExternalLedger(common.LedgerModel):
    __tablename__ = 'external_ledger'

    record_id = db.Column(UUID)
    record_table = db.Column(db.Enum('transaction',
                                     'exchange',
                                     'transfer',
                                     name='record_table_enum'),
                             nullable=False,
                             index=True)
    processor = db.Column(db.String(255), nullable=False, index=True)
    reference_number = db.Column(db.String(255), nullable=False, index=True)
    currency_id = db.Column(db.BigInteger(unsigned=True),
                            db.ForeignKey('currency.id'),
                            nullable=False)
    currency = db.relationship('Currency',
                               backref='external_ledger_entries',
                               lazy='select')
    fee_id = db.Column(db.BigInteger(unsigned=True),
                       db.ForeignKey('fee.id'),
                       nullable=True)
    fee = db.relationship('Fee',
                          backref='external_ledger_entries',
                          lazy='select')
    full_name = db.Column(db.String(255), nullable=True)
コード例 #2
0
ファイル: user.py プロジェクト: pooldin/pooldlib
class User(common.Model,
           common.IDMixin,
           common.NullNameMixin,
           common.EnabledMixin,
           common.VerifiedMixin,
           common.SerializationMixin,
           common.BalanceMixin,
           common.MetadataMixin):

    username = db.Column(db.String(40), unique=True, nullable=False)
    _password = db.Column('password', db.String(64), nullable=False)
    purchases = db.relationship('Purchase', secondary=UserPurchase, backref='purchasing_user')

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

    @password.setter
    def password(self, password):
        self._password = generate_password_hash(password)

    @hybrid_property
    def display_name(self):
        return self.name or self.username

    def __init__(self, *args, **kw):
        super(User, self).__init__(*args, **kw)
        self.update_field('username', kw.get('username'))

        password = kw.get('password')

        if password is not None:
            self.password = password

    def is_password(self, password):
        return check_password_hash(self.password, password)

    def is_anonymous(self):
        return False

    def is_authenticated(self):
        return True

    def is_active(self):
        return self.enabled

    def get_id(self):
        return unicode(self.id)

    @property
    def primary_email(self):
        emails = [e.address for e in self.emails if e.primary]
        if not emails:
            return
        return emails[0]

    def to_dict(self, fields=None):
        fields = fields or ['username', 'display_name', 'about', 'created', 'modified', 'enabled']
        return super(User, self).to_dict(fields=fields)
コード例 #3
0
ファイル: currency.py プロジェクト: pooldin/pooldlib
class Currency(common.DisabledMixin, common.Model):
    title = db.Column(db.String(128))
    code = db.Column(db.String(4), index=True)
    number = db.Column(db.SmallInteger(unsigned=True), index=True)
    unit = db.Column(db.String(32))
    unit_plural = db.Column(db.String(32))
    sign = db.Column(db.String(1))

    @classmethod
    def get(cls, code):
        return cls.query.filter_by(code=code).first()

    def __repr__(self):
        return '<Currency %r>' % self.code or self.title
コード例 #4
0
ファイル: purchase.py プロジェクト: pooldin/pooldlib
class Purchase(common.NameMixin, common.DescriptionMixin, common.Model):
    purchase_ledger_id = db.Column(UUID,
                                   db.ForeignKey('external_ledger.id'),
                                   nullable=False)
    purchase_ledger = db.relationship('ExternalLedger',
                                      backref='purchase',
                                      uselist=False,
                                      lazy='select',
                                      primaryjoin='Purchase.purchase_ledger_id==ExternalLedger.id')
    fulfilled = db.Column(db.Boolean, default=False)
    refunded = db.Column(db.Boolean, default=False)
    refund_ledger_id = db.Column(UUID,
                                 db.ForeignKey('external_ledger.id'),
                                 nullable=False)
    refund_ledger = db.relationship('ExternalLedger',
                                    backref='refund',
                                    uselist=False,
                                    lazy='select',
                                    primaryjoin='Purchase.refund_ledger_id==ExternalLedger.id')

    # These should be migrated to a hstore
    address_one = db.Column(db.String(255))
    address_two = db.Column(db.String(255))
    city = db.Column(db.String(255))
    state = db.Column(db.String(4))
    zip = db.Column(db.String(32))
    country = db.Column(db.String(255))
    email = db.Column(db.String(255), index=True, nullable=False)
コード例 #5
0
ファイル: campaign.py プロジェクト: pooldin/pooldlib
class Invitee(common.UUIDMixin, common.EnabledMixin, common.Model):
    email = db.Column(db.String(255), nullable=False, index=True)
    accepted = db.Column(DateTimeTZ, nullable=True)
    campaign = db.relationship('Campaign', backref='invitees', lazy='select')
    campaign_id = db.Column(db.BigInteger(unsigned=True),
                            db.ForeignKey('campaign.id'),
                            nullable=False)
    user = db.relationship('User', backref='invitations', lazy='select')
    user_id = db.Column(db.BigInteger(unsigned=True),
                        db.ForeignKey('user.id'),
                        nullable=True)

    __table_args__ = (db.UniqueConstraint(campaign_id, email), {})
コード例 #6
0
ファイル: keyvalue.py プロジェクト: pooldin/pooldlib
class KeyValueMixin(object):
    key = db.Column(db.String(64), nullable=False, index=True)
    value = db.Column(db.Text, nullable=False)
コード例 #7
0
ファイル: text.py プロジェクト: pooldin/pooldlib
class NullNameMixin(object):
    name = db.Column(db.String(255))
コード例 #8
0
ファイル: text.py プロジェクト: pooldin/pooldlib
class NameMixin(object):
    name = db.Column(db.String(255), nullable=False)
コード例 #9
0
ファイル: text.py プロジェクト: pooldin/pooldlib
class SlugMixin(object):
    slug = db.Column(db.String(255), nullable=False, unique=True, index=True)