class Target(db.Model):
    id = db.Column(db.Integer(), primary_key=True)

    target_from = db.Column(db.Float(), nullable=True)
    target_to = db.Column(db.Float(), nullable=True)

    indicator_id = db.Column(db.Integer(),
                             db.ForeignKey('indicator.id'),
                             nullable=False)
    objective_id = db.Column(db.Integer(),
                             db.ForeignKey('objective.id', ondelete='CASCADE'),
                             nullable=False)

    username = db.Column(db.String(120), default='')
    created = db.Column(db.DateTime(), default=datetime.utcnow)
    updated = db.Column(db.DateTime(),
                        onupdate=datetime.utcnow,
                        default=datetime.utcnow)

    __table_args__ = (db.UniqueConstraint(
        'indicator_id',
        'objective_id',
        name='target_indicator_id_objective_id_key'), )

    def get_owner(self):
        return self.objective.product.product_group.name

    def __repr__(self):
        return '<Target {} | {} - {}>'.format(self.objective.product.name,
                                              self.target_from, self.target_to)
Esempio n. 2
0
class Hall(db.Model):
    __tablename__ = 'hall'

    id = db.Column(db.Integer(), primary_key=True)
    name = db.Column(db.String(80), nullable=False)
    abbr = db.Column(db.String(10), nullable=True)
    x = db.Column(db.Float())
    y = db.Column(db.Float())

    def __init__(self, name, abbr, x=0, y=0):
        self.name = name
        self.abbr = abbr
        self.x = x
        self.y = y

    def __repr__(self):
        return "<Hall: {}>".format(self.id)

    def json_to_database():
        halls = location.get_halls()['halls']
        print('Writing {} halls to database...'.format(len(halls)))
        for h in halls:
            try:
                hall = Hall(h['name'], h['abbr'], x=h['x'], y=h['y'])
                print('Adding Hall {}, ({}, {})'.format(
                    hall.name, hall.x, hall.y))
                db.session.add(hall)
            except Exception as e:
                print('Error in writing halls to table -- {}'.format(e))
                print('Skipping...')
                continue

        db.session.commit()
Esempio n. 3
0
class Portfolio(db.Model):
    __tablename__ = 'portfolio'

    id = db.Column(db.Integer, primary_key=True)
    date = db.Column(db.DateTime())
    travel_product = db.Column(db.String())
    sessions_ac = db.Column(db.Integer())
    bookings_ac = db.Column(db.Integer())
    revenue_ac = db.Column(db.Integer())
    spend_ac = db.Column(db.Float())
    day_month = db.Column(db.Integer())
    day_week = db.Column(db.Integer())
    week = db.Column(db.Integer())
    month = db.Column(db.Integer())
    quarter = db.Column(db.Integer())
    year = db.Column(db.Integer())
    sessions_aa = db.Column(db.Integer())
    bookings_aa = db.Column(db.Integer())
    revenue_aa = db.Column(db.Integer())
    spend_aa = db.Column(db.Float())
    category = db.Column(db.String())
    birst_category = db.Column(db.String())
    ga_category = db.Column(db.String())

    @staticmethod
    def get_all_blogposts():
        return Portfolio.query.all()

    @staticmethod
    def get_one_blogpost(date):
        return Portfolio.query.get(date)
Esempio n. 4
0
class EducationDetails(db.Model):
    __tablename__ = "education_details"
    id = db.Column(db.GUID(), primary_key=True)
    user_id = db.Column(db.GUID(), db.ForeignKey("users.id"))
    percentage_of_10th = db.Column(db.Float())
    year_of_passing_10th = db.Column(db.Date)
    school_name_of_10th = db.Column(db.String())
    percentage_of_12th = db.Column(db.Float())
    year_of_passing_12th = db.Column(db.Date)
    school_name_of_12th = db.Column(db.String())
    percentage_of_graduation = db.Column(db.Float())
    completion_of_graduation = db.Column(db.Date)
    college_name = db.Column(db.String())
Esempio n. 5
0
class Expense(db.Model):
    expense_id = db.Column(db.String(36), primary_key=True)
    user_id = db.Column(db.String(36), nullable=False)
    amount = db.Column(db.Float(), nullable=False)
    description = db.Column(db.String(100))
    created_at = db.Column(db.DateTime, default=func.now())
    category_id = db.Column(
        db.String(36), db.ForeignKey("category.category_id"))
    category = db.relationship(Category, backref=db.backref('expenses'))
Esempio n. 6
0
class Order(db.Model):
    __tablename__ = 'order'

    id = db.Column(db.Integer(), primary_key=True)
    date = db.Column(db.DateTime, default=datetime.datetime.utcnow)
    status = db.Column(db.Enum(OrderStatusEnum))
    price = db.Column(db.Float())
    customer_id = db.Column(db.Integer, db.ForeignKey('customer.id'))
    customer = relationship(Customer)
Esempio n. 7
0
class Movie(db.Model):
    __tablename__ = 'movie'
    id = db.Column(db.Integer, primary_key=True)
    img = db.Column(db.Text())
    name = db.Column(db.String(64))
    actor = db.Column(db.Text())
    up_time = db.Column(db.DateTime())
    score = db.Column(db.Float())

    def __repr__(self):
        return '<User %r>' % self.name
Esempio n. 8
0
class GeoData(db.Model):
    __tablename__ = 'geodata'

    id = db.Column(db.Integer, primary_key=True)
    name_1 = db.Column(db.String())
    name_2 = db.Column(db.String())
    cc_2 = db.Column(db.String())
    nat2018 = db.Column(db.Float())
    geometry = db.Column(db.String())

    def __repr__(self):
        return "<User: {}>".format(self.username)
Esempio n. 9
0
class Service(db.Model):
    __tablename__ = 'Service'
    ID = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(64), nullable=False)
    rate = db.Column(db.Float(), nullable=False)
    add_by = db.Column(db.Integer, db.ForeignKey('User.ID'))

    user = db.relationship('User', back_populates='service')
    appointment = db.relationship('Appointment', back_populates='service')

    # def __repr__(self):
    #     return f'<{self.name}, charges {self.rate} per hour>'

    # 输入服务名称,返回该服务的信息
    def get_rate(self, service):
        return Service.query.filter_by(name=service).first()
Esempio n. 10
0
class BotMetaDetails(db.Model):
        __tablename__ = 'bot_meta_details'
        id = db.Column(db.GUID(), primary_key=True)
        user_id = db.Column(db.GUID(), db.ForeignKey('users.id'))
        selected_categories = db.Column(postgresql.ARRAY(db.GUID()))
        accuracy = db.Column(db.Float())
Esempio n. 11
0
class Invoice(ResourceMixin, db.Model):
    __tablename__ = 'invoices'
    id = db.Column(db.Integer, primary_key=True)

    # Relationships.
    user_id = db.Column(db.Integer, db.ForeignKey('users.id',
                                                  onupdate='CASCADE',
                                                  ondelete='CASCADE'),
                        index=True, nullable=False)

    # Invoice details.
    plan = db.Column(db.String(128), index=True)
    receipt_number = db.Column(db.String(128), index=True)
    description = db.Column(db.String(128))
    period_start_on = db.Column(db.Date)
    period_end_on = db.Column(db.Date)
    currency = db.Column(db.String(8))
    tax = db.Column(db.Integer())
    tax_percent = db.Column(db.Float())
    total = db.Column(db.Integer())

    # De-normalize the card details so we can render a user's history properly
    # even if they have no active subscription or changed cards at some point.
    brand = db.Column(db.String(32))
    last4 = db.Column(db.Integer)
    exp_date = db.Column(db.Date, index=True)

    def __init__(self, **kwargs):
        # Call Flask-SQLAlchemy's constructor.
        super(Invoice, self).__init__(**kwargs)

    @classmethod
    def billing_history(cls, user=None):
        """
        Return the billing history for a specific user.

        :param user: User whose billing history will be retrieved
        :type user: User instance

        :return: Invoices
        """
        invoices = Invoice.query.filter(Invoice.user_id == user.id) \
            .order_by(Invoice.created_on.desc()).limit(12)

        return invoices

    @classmethod
    def parse_from_event(cls, payload):
        """
        Parse and return the invoice information that will get saved locally.

        :return: dict
        """
        data = payload['data']['object']
        plan_info = data['lines']['data'][0]['plan']

        period_start_on = datetime.datetime.utcfromtimestamp(
            data['lines']['data'][0]['period']['start']).date()
        period_end_on = datetime.datetime.utcfromtimestamp(
            data['lines']['data'][0]['period']['end']).date()

        invoice = {
            'payment_id': data['customer'],
            'plan': plan_info['name'],
            'receipt_number': data['receipt_number'],
            'description': plan_info['statement_descriptor'],
            'period_start_on': period_start_on,
            'period_end_on': period_end_on,
            'currency': data['currency'],
            'tax': data['tax'],
            'tax_percent': data['tax_percent'],
            'total': data['total']
        }

        return invoice

    @classmethod
    def parse_from_api(cls, payload):
        """
        Parse and return the invoice information we are interested in.

        :return: dict
        """
        plan_info = payload['lines']['data'][0]['plan']
        date = datetime.datetime.utcfromtimestamp(payload['date'])
        invoice = {
            # 'plan': plan_info['name'],
            # 'description': plan_info['statement_descriptor'],
            # 'next_bill_on': date,
            # 'amount_due': payload['amount_due'],
            # 'interval': plan_info['interval']
            'plan': plan_info['id'].title(),
            'description': plan_info['id'].title(),
            'next_bill_on': date,
            'amount_due': plan_info['amount'],
            'interval': plan_info['interval']
        }

        return invoice

    @classmethod
    def prepare_and_save(cls, parsed_event):
        """
        Potentially save the invoice after argument the event fields.

        :param parsed_event: Event params to be save
        :type parsed_event: dict
        :return: User instance
        """
        # Avoid circular imports.
        from app.blueprints.user.models import User

        # Only save the invoice if the user is valid at this point.
        id = parsed_event.get('payment_id')
        user = User.query.filter((User.payment_id == id)).first()

        if user and user.credit_card:
            parsed_event['user_id'] = user.id
            parsed_event['brand'] = user.credit_card.brand
            parsed_event['last4'] = user.credit_card.last4
            parsed_event['exp_date'] = user.credit_card.exp_date

            del parsed_event['payment_id']

            invoice = Invoice(**parsed_event)
            invoice.save()

        return user

    @classmethod
    def upcoming(cls, customer_id):
        """
        Return the upcoming invoice item.

        :param customer_id: Stripe customer id
        :type customer_id: int
        :return: Stripe invoice object
        """
        invoice = PaymentInvoice.upcoming(customer_id)

        return Invoice.parse_from_api(invoice)
Esempio n. 12
0
class Offer(db.Model, BaseMixin, ModelHelper):
    __tablename__ = 'offers'
    __table_args__ = {'extend_existing': True}
    id = db.Column(GUID(), primary_key=True, default=uuid4)
    alias = db.Column(db.String(20), unique=True, nullable=False)
    name = db.Column(db.String(100), nullable=False)
    geo = db.Column(db.String(20), nullable=True)
    img = db.Column(db.Text, nullable=True)
    category_id = db.Column(GUID(),
                            db.ForeignKey('categories.id', ondelete="CASCADE"),
                            nullable=True)
    category = db.relationship('Category')
    description = db.Column(db.Text, nullable=True)
    short_desc = db.Column(db.Text, nullable=True)
    country_code = db.Column(db.String(20), nullable=True)
    payout_share = db.Column(db.Float(), nullable=True, default=0.0)
    ecpc = db.Column(db.Float(), nullable=True, default=0.0)
    price = db.Column(db.Float(), nullable=True, default=0.0)
    meta_data = db.Column(db.JSON(), nullable=True, default=None)
    adv_id = db.Column(GUID(),
                       db.ForeignKey('advs.id', ondelete="CASCADE"),
                       nullable=True)

    @staticmethod
    def from_arguments(args):
        """
            arguments from create offer
            'alias': {'type': 'string'},
            'description': {'type': 'string'},
            'short_desc': {'type': 'string'},
            'geo': {'type': 'string'},
            'name': {'type': 'string'},
            'img': {'type': 'string', 'format': 'uri'},
            'category_id': {'type': 'string', 'format': 'uuid'},
            'country_code': {'type': 'integer'},
            'payout_share': {'type': 'number'},
            'ecpc': {'type': 'number'},
            'price': {'type': 'number'},
            'adv_id': {'type': 'string', 'format': 'uuid'},
            'aff_sub_pub': {'type': 'string'},
            'aff_sub_order': {'type': 'string'},
            'aff_click_id': {'type': 'string'},
            'aff_pub_sub2': {'type': 'string'},
            'account_name':  {'type': 'string'},
            'required': ['name', 'alias', 'description', 'category_id', 'adv_id', 'price', 'img'],
        """
        name = args.get('name')
        alias = args.get('alias')
        geo = args.get('geo', 'global')
        price = args.get('price', 0.0)
        payout_share = args.get('payout_share', 0.0)
        ecpc = args.get('ecpec', 0.0)
        img = args.get('img')
        adv_id = args.get('adv_id')
        category_id = args.get('category_id')
        aff_sub_pub = args.get('aff_sub_pub')
        aff_sub_order = args.get('aff_sub_order')
        aff_click_id = args.get('aff_click_id')
        aff_pub_sub2 = args.get('aff_pub_sub2')
        description = args.get('description')
        short_desc = args.get('short_desc')
        account_name = args.get('account_name')
        meta_data = {
            'aff_sub_pub': aff_sub_pub,
            'aff_sub_order': aff_sub_order,
            'aff_click_id': aff_click_id,
            'aff_pub_sub2': aff_pub_sub2,
            'account_name': account_name
        }
        offer = Offer(name=name,
                      alias=alias,
                      geo=geo,
                      price=price,
                      payout_share=payout_share,
                      ecpc=ecpc,
                      img=img,
                      adv_id=adv_id,
                      category_id=category_id,
                      description=description,
                      short_desc=short_desc,
                      meta_data=meta_data)
        return offer