コード例 #1
0
ファイル: api.py プロジェクト: dabhanddevelopments/Alpheus
 def set_fields(field, name, group):
     extra_fields = ['cash_flow_euro_amount_euro_dollar', 'cash_flow_percent_euro_dollar']
     dic = {'type': name, 'group': group}
     for row in data['objects']:
         month = row.data['value_date'].month
         month_name = calendar.month_abbr[month].lower()
         dic[month_name] = row.data[field]
         for extra_field in extra_fields:
             dic[extra_field] = row.data[extra_field]
     fields.append(dic)
コード例 #2
0
ファイル: api.py プロジェクト: dabhanddevelopments/Alpheus
 def set_fields(field, group, extra_fields = []):
     dic = {'type': field.replace('_', ' ').title(), 'group': group}
     for row in data['objects']:
         if row.data['holding__name'] == group:
             month = row.data['value_date'].month
             month_name = calendar.month_abbr[month].lower()
             dic[month_name] = row.data[field]
             for extra_field in extra_fields:
                 dic[extra_field] = row.data[extra_field]
     fields.append(dic)
コード例 #3
0
    def dehydrate_fields(self, bundle):
        resource_klass = bundle.obj.get_class()

        fields = []
        for name, attr in resource_klass.get_all_attribute_properties():
            fields.append({
                "label": attr.get_label(name),
                "name": name,
                "optional": attr.optional,
                "user_read_only": attr.user_read_only,
                "class": attr.__class__.__name__,
            })
        return fields
コード例 #4
0
    def dehydrate_fields(self, bundle):
        resource_klass = bundle.obj.get_class()

        fields = []
        for name, attr in resource_klass.get_all_attribute_properties():
            fields.append({
                'label': attr.get_label(name),
                'name': name,
                'optional': attr.optional,
                'user_read_only': attr.user_read_only,
                'class': attr.__class__.__name__
            })
        return fields
コード例 #5
0
ファイル: v0_5.py プロジェクト: caktus/commcare-hq
    def obj_get_list(self, bundle, **kwargs):
        request_fields = bundle.request.GET.getlist('fields')
        for field in request_fields:
            if field not in self.fields:
                raise BadRequest('{0} is not a valid field'.format(field))

        params = bundle.request.GET
        param = lambda p: params.get(p, None)
        fields = list(self.fields)
        fields.remove('id')
        fields.append('_id')
        fn = MOCK_BULK_USER_ES or user_es_call
        users = fn(
            domain=kwargs['domain'],
            q=param('q'),
            fields=fields,
            size=param('limit'),
            start_at=param('offset'),
        )
        return list(map(self.to_obj, users))
コード例 #6
0
ファイル: v0_5.py プロジェクト: tlwakwella/commcare-hq
    def obj_get_list(self, bundle, **kwargs):
        request_fields = bundle.request.GET.getlist('fields')
        for field in request_fields:
            if field not in self.fields:
                raise BadRequest('{0} is not a valid field'.format(field))

        params = bundle.request.GET
        param = lambda p: params.get(p, None)
        fields = self.fields.keys()
        fields.remove('id')
        fields.append('_id')
        fn = MOCK_BULK_USER_ES or user_es_call
        users = fn(
            domain=kwargs['domain'],
            q=param('q'),
            fields=fields,
            size=param('limit'),
            start_at=param('offset'),
        )
        return map(self.to_obj, users)
コード例 #7
0
    def get_list(self, request, **kwargs):

        base_bundle = self.build_bundle(request=request)
        benchmarks = self.obj_get_list(bundle=base_bundle,
                    **self.remove_api_resource_names(kwargs))

        FundPerfMonth.objects.select_related('fund')
        fund = request.GET.get('funds', 0)
        funds = FundPerfMonth.objects.select_related('fund') \
                            .filter(year__fund=fund).latest('value_date')

        # rows
        rows = ['ann_return1', 'ann_volatility1', 'sharpe_ratio1']
        data = []
        for index, row in enumerate(rows):
            dic = {}
            dic['type'] = row.title().replace('_', ' ')
            dic['fund_name'] = getattr(funds, row)
            for index, bench in enumerate(benchmarks):
                history = FundBenchHist.objects.filter(benchmark=bench.id) \
                                                        .latest('value_date')
                dic['benchmark_' + str(index + 1)] = getattr(history, row)
            data.append(dic)

        # get latest SI
        funds = FundPerfMonth.objects.filter(fund=fund).latest('value_date')
        data.append({'type': 'Since Inception', 'fund_name': funds.si})

        # columns
        fields = ['type', ['fund_name', funds.fund.name]]
        for index, field in enumerate(benchmarks):
            fields.append('benchmark_' + str(index + 1))
        columns = self.set_columns(fields, [100, 100])

        dic = {
            'metaData': {'sorting': 'name'},
            'columns': columns,
            'rows': data,
        }
        return JsonResponse(dic)
コード例 #8
0
 def create_table(self, request, name, geojson_data):
     tr = TablesResource()
     feature = geojson_data['features'][0]
     props = feature['properties']
     geom_type, is_3d = self.get_geometry_type(geojson_data)
     fields = []
     for k, v in props.iteritems():
         if isinstance(v, (int, long)):
             ftype = 'integer'
         elif isinstance(v, (float)):
             ftype = 'float'
         else:
             ftype = 'text'
         fields.append({
             'name': k,
             'type': ftype,
         })
     bundle = tr.build_bundle(request=request,
                              data=dict(name=name,
                                        geometry_type=geom_type,
                                        is_3d=is_3d,
                                        fields=fields))
     return tr.obj_create(bundle)