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)
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)
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
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)
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), {})
class KeyValueMixin(object): key = db.Column(db.String(64), nullable=False, index=True) value = db.Column(db.Text, nullable=False)
class NullNameMixin(object): name = db.Column(db.String(255))
class NameMixin(object): name = db.Column(db.String(255), nullable=False)
class SlugMixin(object): slug = db.Column(db.String(255), nullable=False, unique=True, index=True)