Exemplo n.º 1
0
class CustomerData(Thing):
    __tablename__ = 'customer_data'

    id = db.Column(db.Integer, db.ForeignKey('thing.id'), primary_key=True)

    email = db.Column(db.String(128))

    phone = db.Column(db.String(32))

    __mapper_args__ = {
        'polymorphic_identity': 'customer_data',
    }
Exemplo n.º 2
0
class CreditCard(Thing):
    __tablename__ = 'credit_card'

    id = db.Column(db.Integer, db.ForeignKey('thing.id'), primary_key=True)

    number = db.Column(db.String(32))

    card_code = db.Column(db.String(8))

    expiration_date = db.Column(db.String(8))

    __mapper_args__ = {
        'polymorphic_identity': 'credit_card',
    }
Exemplo n.º 3
0
class Audience(Thing):
    __tablename__ = 'audience'

    id = db.Column(db.Integer, db.ForeignKey('thing.id'), primary_key=True)

    # The target group associated with a given audience
    # (e.g. veterans, car owners, musicians, etc.)
    audience_type = db.Column(db.String(256))

    # events = db.relationship('Event', backref='audience', lazy='dynamic')

    __mapper_args__ = {
        'polymorphic_identity': 'audience',
    }
Exemplo n.º 4
0
class TransactionResponse(Thing):
    __tablename__ = 'transaction_response'

    id = db.Column(db.Integer, db.ForeignKey('thing.id'), primary_key=True)

    response_code = db.Column(db.String(16))

    approved = db.Column(db.Boolean)

    response_body = db.Column(db.Text)

    __mapper_args__ = {
        'polymorphic_identity': 'transaction_response',
    }
Exemplo n.º 5
0
class Payment(Thing):
    __tablename__ = 'payment'

    id = db.Column(db.Integer, db.ForeignKey('thing.id'), primary_key=True)

    payment_type = db.Column(db.String(32))

    credit_card_id = db.Column(db.Integer, db.ForeignKey('credit_card.id'))
    credit_card = db.relationship('CreditCard',
                                  backref='payment',
                                  foreign_keys=[credit_card_id])

    __mapper_args__ = {
        'polymorphic_identity': 'payment',
    }
Exemplo n.º 6
0
class Post(db.Model):
    id = db.Column(db.Integer, primary_key=True)

    body = db.Column(db.Text)

    timestamp = db.Column(db.DateTime, index=True, default=datetime.now)

    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    author = db.relationship('User', foreign_keys=[user_id])

    thing_id = db.Column(db.Integer, db.ForeignKey('thing.id'))
    thing = db.relationship('Thing', foreign_keys=[thing_id])

    def __repr__(self):
        return '<Post {}>'.format(self.body)
Exemplo n.º 7
0
class Order(Thing):
    __tablename__ = 'order'

    id = db.Column(db.Integer, db.ForeignKey('thing.id'), primary_key=True)

    __mapper_args__ = {
        'polymorphic_identity': 'order',
    }
Exemplo n.º 8
0
class Ticket(Thing):

    id = db.Column(db.Integer, db.ForeignKey('thing.id'), primary_key=True)

    face_value = db.Column(db.Numeric(12, 2))

    event_id = db.Column(db.Integer, db.ForeignKey('event.id'))
    event = db.relationship('Event', foreign_keys=[event_id])

    reservation_id = db.Column(db.Integer, db.ForeignKey('reservation.id'))
    reservation = db.relationship('Reservation',
                                  foreign_keys=[reservation_id],
                                  backref='tickets')

    offer_id = db.Column(db.Integer, db.ForeignKey('offer.id'))
    offer = db.relationship('Offer', foreign_keys=[offer_id])

    __mapper_args__ = {'polymorphic_identity': 'ticket'}
Exemplo n.º 9
0
class LineItem(Thing):
    __tablename__ = 'line_item'

    id = db.Column(db.Integer, db.ForeignKey('thing.id'), primary_key=True)

    transaction_request_id = db.Column(db.Integer,
                                       db.ForeignKey('transaction_request.id'))
    transaction_request = db.relationship(
        'TransactionRequest',
        foreign_keys=[transaction_request_id],
        backref='line_items')

    unit_price = db.Column(db.Numeric(12, 2))

    fee = db.Column(db.Numeric(12, 2))

    quantity = db.Column(db.Integer)

    __mapper_args__ = {
        'polymorphic_identity': 'line_item',
    }
Exemplo n.º 10
0
class TransactionRequest(Thing):
    __tablename__ = 'transaction_request'

    id = db.Column(db.Integer, db.ForeignKey('thing.id'), primary_key=True)

    # The amount of the transaction request
    amount = db.Column(db.Numeric(12, 2))
    taxes = db.Column(db.Numeric(12, 2))
    fees = db.Column(db.Numeric(12, 2))

    payment_id = db.Column(db.Integer, db.ForeignKey('payment.id'))
    payment = db.relationship('Payment',
                              backref='transaction_request',
                              foreign_keys=[payment_id])

    order_id = db.Column(db.Integer, db.ForeignKey('order.id'))
    order = db.relationship('Order',
                            backref='transaction_request',
                            foreign_keys=[order_id])

    customer_address_id = db.Column(db.Integer,
                                    db.ForeignKey('customer_address.id'))
    bill_to = db.relationship('CustomerAddress',
                              backref='transaction_request',
                              foreign_keys=[customer_address_id])

    customer_data_id = db.Column(db.Integer, db.ForeignKey('customer_data.id'))
    customer = db.relationship('CustomerData',
                               backref='transaction_request',
                               foreign_keys=[customer_data_id])

    transaction_response_id = db.Column(
        db.Integer, db.ForeignKey('transaction_response.id'))
    transaction_response = db.relationship(
        'TransactionResponse',
        backref='transaction_request',
        foreign_keys=[transaction_response_id])

    __mapper_args__ = {
        'polymorphic_identity': 'transaction_request',
    }
Exemplo n.º 11
0
class CustomerAddress(Thing):
    __tablename__ = 'customer_address'

    id = db.Column(db.Integer, db.ForeignKey('thing.id'), primary_key=True)

    first_name = db.Column(db.String(256))

    last_name = db.Column(db.String(256))

    company = db.Column(db.String(256))

    address = db.Column(db.String(256))

    city = db.Column(db.String(256))

    state = db.Column(db.String(256))

    zip = db.Column(db.String(256))

    __mapper_args__ = {
        'polymorphic_identity': 'customer_address',
    }
Exemplo n.º 12
0
class User(UserMixin, db.Model):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(64), index=True, unique=True)
    email = db.Column(db.String(120), index=True, unique=True)
    password_hash = db.Column(db.String(128))
    about_me = db.Column(db.String(140))
    last_seen = db.Column(db.DateTime)

    def get_reset_password_token(self, expires_in=600):
        return jwt.encode(
            {
                'reset_password': self.id,
                'exp': time() + expires_in
            },
            current_app.config['SECRET_KEY'],
            algorithm='HS256').decode('utf-8')

    @staticmethod
    def verify_reset_password_token(token):
        try:
            id = jwt.decode(token,
                            current_app.config['SECRET_KEY'],
                            algorithms=['HS256'])['reset_password']
        except:
            return

        return User.query.get(id)

    def set_password(self, password):
        self.password_hash = generate_password_hash(password)

    def check_password(self, password):
        return check_password_hash(self.password_hash, password)

    def avatar(self, size):
        digest = md5(self.email.lower().encode('utf-8')).hexdigest()

        return 'https://www.gravatar.com/avatar/{}?d=identicon&s={}'.format(
            digest, size)

    def __repr__(self):
        return '<User {}>'.format(self.username)
Exemplo n.º 13
0
class Reservation(Thing):
    __tablename__ = 'reservation'

    id = db.Column(db.Integer, db.ForeignKey('thing.id'), primary_key=True)

    booking_time = db.Column(db.DateTime, default=datetime.now)

    reservation_for_id = db.Column(db.Integer, db.ForeignKey('event.id'))
    reservation_for = db.relationship('Event',
                                      foreign_keys=[reservation_for_id],
                                      backref='reservations')

    under_name = db.Column(db.String(256))

    total_price = db.Column(db.Numeric(12, 2))

    transaction_request_id = db.Column(db.Integer,
                                       db.ForeignKey('transaction_request.id'))
    transaction_request = db.relationship(
        'TransactionRequest', foreign_keys=[transaction_request_id])

    __mapper_args__ = {'polymorphic_identity': 'reservation'}
Exemplo n.º 14
0
class Thing(db.Model):
    __tablename__ = 'thing'

    id = db.Column(db.Integer, primary_key=True)

    # The type of the item
    type = db.Column(db.String(50))

    # UUID of item
    uuid = db.Column(db.String(64), default=get_uuid)

    # An alias for the item
    alternate_name = db.Column(db.String(256))

    # A description of the item
    description = db.Column(db.String(1024))

    # A sub property of description. A short description of the
    # item used to disambiguate from other, similar items. Information
    # from other properties (in particular, name) may be necessary for
    # the description to be useful for disambiguation.
    disambiguating_description = db.Column(db.String(1024))

    # The identifier property represents any kind of identifier for any
    # kind of Thing, such as ISBNs, GTIN codes, UUIDs etc.
    identifier = db.Column(db.String(256))

    # An image of the item
    image = db.Column(db.String(256))

    # Indicates a page for which this thing is the main entity being described.
    main_entity_of_page = db.Column(db.String(256))

    # The name of the item.
    name = db.Column(db.String(256))

    # URL of the item.
    url = db.Column(db.String(256))

    # IP Address
    ip_address = db.Column(db.String(32))

    created = db.Column(db.DateTime, default=datetime.now)
    created_by = db.Column(db.String(64))

    modified = db.Column(db.DateTime, default=datetime.now)
    modified_by = db.Column(db.String(64))

    is_default = db.Column(db.Boolean)

    comments = db.relationship('Post')

    __mapper_args__ = {
        'polymorphic_identity': 'thing',
        'polymorphic_on': type
    }
Exemplo n.º 15
0
class Event(Thing):
    __tablename__ = 'event'

    id = db.Column(db.Integer, db.ForeignKey('thing.id'), primary_key=True)

    parent_id = db.Column(db.Integer, db.ForeignKey('event.id'))
    parent = db.relationship('Event',
                             remote_side=[id],
                             foreign_keys=[parent_id])

    door_time = db.Column(db.DateTime, index=True)

    start_time_ = db.Column('start_time', db.DateTime, index=True)
    end_time = db.Column(db.DateTime, index=True)

    @property
    def start_time(self):
        eastern = timezone('US/Eastern')

        return self.start_time_.replace(tzinfo=pytz.UTC).astimezone(eastern)

    @start_time.setter
    def start_time(self, value):
        self.start_time_ = value

    start_time = synonym('start_time_', descriptor=start_time)

    maximum_attendee_capacity = db.Column(db.Integer)

    child_events = db.relationship('Event', foreign_keys=[parent_id])

    audience_id = db.Column(db.Integer, db.ForeignKey('audience.id'))
    audience = db.relationship("Audience", foreign_keys=[audience_id])

    # Slug for site url
    slug = db.Column(db.String(256))

    # Shorthand code that will show up on the calendar
    calendar_code = db.Column(db.String(16))

    # Two images per show/event
    primary_image = db.Column(db.String(128))
    secondary_image = db.Column(db.String(128))

    offers = db.relationship('Offer', secondary=event_offer)

    #tickets = db.relationship('Ticket', back_populates='event')

    is_active = db.Column(db.Boolean, default=True)

    is_basic = db.Column(db.Boolean, default=True)

    def __repr__(self):
        return '<Event {}: {}>'.format(self.name, self.start_time)

    __mapper_args__ = {
        'polymorphic_identity': 'event',
    }
Exemplo n.º 16
0
from juniper.app.main.models import Thing
from juniper.app import db
from sqlalchemy.orm import synonym
from pytz import timezone
import pytz

event_offer = db.Table(
    'event_offer', db.Column('event_id', db.Integer,
                             db.ForeignKey('event.id')),
    db.Column('offer_id', db.Integer, db.ForeignKey('offer.id')))


class Event(Thing):
    __tablename__ = 'event'

    id = db.Column(db.Integer, db.ForeignKey('thing.id'), primary_key=True)

    parent_id = db.Column(db.Integer, db.ForeignKey('event.id'))
    parent = db.relationship('Event',
                             remote_side=[id],
                             foreign_keys=[parent_id])

    door_time = db.Column(db.DateTime, index=True)

    start_time_ = db.Column('start_time', db.DateTime, index=True)
    end_time = db.Column(db.DateTime, index=True)

    @property
    def start_time(self):
        eastern = timezone('US/Eastern')