Ejemplo n.º 1
0
 def __init__(self, params, model_name, r_id):
     self.model = get_model_class(model_name)
     self.r_id = r_id
     self.stripe = stripe
     self.stripe.api_key = settings.FOREST_STRIPE_API_KEY
     self.user_field = settings.FOREST_STRIPE_USER_FIELD
     self.params = params
Ejemplo n.º 2
0
 def __init__(self, request, model, r_id=None, association=None):
     self.request = request
     self.params = request.GET
     self.model = utils.get_model_class(model)
     self.count = 0
     self.r_id = r_id
     self.association = association
Ejemplo n.º 3
0
def perform(params, model_name):
    model = utils.get_model_class(model_name)
    filters = _get_filters(params)
    select = _get_custom_select(params)
    values = select.keys()
    aggregate = _get_aggregate(params)
    query = model.objects.filter(**filters).extra(select=select).values(
        *values)
    query = query.annotate(value=aggregate(params.get('group_by_date_field')))
    data = list(query)
    _format_data(data, params)
    return {'value': data}
Ejemplo n.º 4
0
def perform(params, model_name):
    model = utils.get_model_class(model_name)
    aggregate_field = _get_aggregate_field(params)
    aggregate = _get_aggregate(params)
    filters = _get_filters(params)
    query = model.objects
    if filters:
        query = query.filter(**filters)
    data = query.aggregate(aggregate(aggregate_field))
    generated_field = "%s__%s" % (aggregate_field,
                                  params.get('aggregate').lower())
    count = data[generated_field]
    return {'value': {'countCurrent': count}}
Ejemplo n.º 5
0
def perform(request, model_name, r_id, association):
    model = utils.get_model_class(association)
    filter_key = _get_q_filter_key(model_name, association)
    q_filter = {'%s' % filter_key: r_id}
    #TODO: is this useful?
    related_fields = [
        f.name for f in model._meta.get_fields() if isinstance(f, ForeignKey)
    ]
    params = request.GET
    limit = _handle_limit(params)
    offset = _handle_offset(params, limit)
    sort = _handle_sort(params)
    query = model.objects.select_related(*related_fields).filter(**q_filter)
    count = query.count()
    if sort:
        query = query.order_by(sort)

    return query[offset:offset + limit], count
Ejemplo n.º 6
0
def perform(params, model_name):
    model = utils.get_model_class(model_name)
    group_by_field = _get_group_by(params)
    aggregate = _get_aggregate(params)
    filters = _get_filters(params)
    query = model.objects
    query = query.filter(**filters)
    query = query.values(group_by_field)
    query = query.annotate(value=aggregate(group_by_field))

    # The following cast to list is necessary to override the "remaining
    # elements truncated" limitation of django queryset result. Maybe there's a
    # better way.
    # TODO: Should we set a limit? Would make sense for pie charts.

    data = list(query.order_by('-value'))
    for item in data:
        item['key'] = item.pop(group_by_field)

    return {'value': data}
Ejemplo n.º 7
0
def _get_q_filter_key(model_name, association):
    model = utils.get_model_class(association)
    fields = model._meta.get_fields()
    for field in fields:
        if field.is_relation and field.related_model.__name__ == model_name:
            return field.name
Ejemplo n.º 8
0
def setup_stripe_integration(apimap):
    model = get_model_class(settings.FOREST_STRIPE_USER_COLLECTION)
    reference_name = model.__name__
    apimap.append({
        'name':
        'stripe_payments',
        'isVirtual':
        True,
        'isReadOnly':
        True,
        'fields': [{
            'field': 'id',
            'type': 'String',
            'isSearchable': False
        }, {
            'field': 'created',
            'type': 'Date',
            'isSearchable': False
        }, {
            'field': 'amount',
            'type': 'Number',
            'isSearchable': False
        }, {
            'field': 'status',
            'type': 'String',
            'isSearchable': False
        }, {
            'field': 'currency',
            'type': 'String',
            'isSearchable': False
        }, {
            'field': 'refunded',
            'type': 'Boolean',
            'isSearchable': False
        }, {
            'field': 'description',
            'type': 'String',
            'isSearchable': False
        }, {
            'field': 'customer',
            'type': 'String',
            'reference': reference_name,
            'isSearchable': False
        }],
        'actions': [{
            'name': 'Refund',
            'endpoint': '/forest/stripe_payments/refunds'
        }]
    })

    apimap.append({
        'name':
        'stripe_invoices',
        'isVirtual':
        True,
        'isReadOnly':
        True,
        'fields': [{
            'field': 'id',
            'type': 'String',
            'isSearchable': False
        }, {
            'field': 'amount_due',
            'type': 'Number',
            'isSearchable': False
        }, {
            'field': 'attempt_count',
            'type': 'Number',
            'isSearchable': False
        }, {
            'field': 'attempted',
            'type': 'Boolean',
            'isSearchable': False
        }, {
            'field': 'closed',
            'type': 'Boolean',
            'isSearchable': False
        }, {
            'field': 'currency',
            'type': 'String',
            'isSearchable': False
        }, {
            'field': 'date',
            'type': 'Date',
            'isSearchable': False
        }, {
            'field': 'forgiven',
            'type': 'Boolean',
            'isSearchable': False
        }, {
            'field': 'period_start',
            'type': 'Date',
            'isSearchable': False
        }, {
            'field': 'period_end',
            'type': 'Date',
            'isSearchable': False
        }, {
            'field': 'subtotal',
            'type': 'Number',
            'isSearchable': False
        }, {
            'field': 'total',
            'type': 'Number',
            'isSearchable': False
        }, {
            'field': 'application_fee',
            'type': 'Number',
            'isSearchable': False
        }, {
            'field': 'tax',
            'type': 'Number',
            'isSearchable': False
        }, {
            'field': 'tax_percent',
            'type': 'Number',
            'isSearchable': False
        }, {
            'field': 'customer',
            'type': 'String',
            'reference': reference_name,
            'isSearchable': False
        }]
    })

    apimap.append({
        'name':
        'stripe_cards',
        'isVirtual':
        True,
        'isReadOnly':
        True,
        'onlyForRelationships':
        True,
        'fields': [{
            'field': 'id',
            'type': 'String',
            'isSearchable': False
        }, {
            'field': 'last4',
            'type': 'String',
            'isSearchable': False
        }, {
            'field': 'brand',
            'type': 'String',
            'isSearchable': False
        }, {
            'field': 'funding',
            'type': 'String',
            'isSearchable': False
        }, {
            'field': 'exp_month',
            'type': 'Number',
            'isSearchable': False
        }, {
            'field': 'exp_year',
            'type': 'Number',
            'isSearchable': False
        }, {
            'field': 'country',
            'type': 'String',
            'isSearchable': False
        }, {
            'field': 'name',
            'type': 'String',
            'isSearchable': False
        }, {
            'field': 'address_line1',
            'type': 'String',
            'isSearchable': False
        }, {
            'field': 'address_line2',
            'type': 'String',
            'isSearchable': False
        }, {
            'field': 'address_city',
            'type': 'String',
            'isSearchable': False
        }, {
            'field': 'address_state',
            'type': 'String',
            'isSearchable': False
        }, {
            'field': 'address_zip',
            'type': 'String',
            'isSearchable': False
        }, {
            'field': 'address_country',
            'type': 'String',
            'isSearchable': False
        }, {
            'field': 'cvc_check',
            'type': 'String',
            'isSearchable': False
        }, {
            'field': 'customer',
            'type': 'String',
            'reference': reference_name,
            'isSearchable': False
        }]
    })
Ejemplo n.º 9
0
 def __init__(self, request, model_name):
     self.body = json.loads(request.body)
     self.model_name = model_name
     self.model = get_model_class(model_name)
Ejemplo n.º 10
0
 def __init__(self, request, model_name, r_id):
     self.model = get_model_class(model_name)
     self.r_id = r_id