Exemple #1
0
    def get(self):
        parser.add_argument('q', type=unicode)
        args = parser.parse_args()
        limit = min(
            args.get('limit') or current_app.config.get('PAGE_SIZE'),
            current_app.config.get('PAGE_SIZE'))
        offset = args.get('offset') or 0

        queryset = services.locations.find()

        # do location lookups
        if 'q' in args and args.get('q'):
            queryset = queryset.filter(
                Q(name__icontains=args.get('q'))
                | Q(code__istartswith=args.get('q'))
                | Q(political_code__istartswith=args.get('q'))).order_by(
                    'ancestor_count')

        queryset = queryset.limit(limit).skip(offset)

        dataset = marshal(list(queryset), LOCATION_FIELD_MAPPER)

        result = {
            'meta': {
                'limit': limit,
                'offset': offset,
                'total': queryset.count(False)
            },
            'objects': dataset
        }

        return jsonify(result)
Exemple #2
0
    def get(self):
        parser.add_argument('q', type=unicode)
        args = parser.parse_args()
        limit = min(
            args.get('limit') or current_app.config.get('PAGE_SIZE'),
            current_app.config.get('PAGE_SIZE'))
        offset = args.get('offset') or 0

        queryset = services.locations.find()

        # do location lookups
        if 'q' in args and args.get('q'):
            queryset = queryset.filter(
                Q(name__icontains=args.get('q')) |
                Q(code__istartswith=args.get('q')) |
                Q(political_code__istartswith=args.get('q'))
            ).order_by('ancestor_count')

        queryset = queryset.limit(limit).skip(offset)

        dataset = marshal(
            list(queryset),
            LOCATION_FIELD_MAPPER
        )

        result = {
            'meta': {
                'limit': limit,
                'offset': offset,
                'total': queryset.count(False)
            },
            'objects': dataset
        }

        return jsonify(result)
Exemple #3
0
    def get(self):
        # marshal() can also handle a list or tuple of objects, but it only
        # checks for a list or tuple, so we need to convert the queryset
        # to a list
        args = parser.parse_args()
        limit = min(
            args.get('limit') or current_app.config.get('PAGE_SIZE'),
            current_app.config.get('PAGE_SIZE'))
        offset = args.get('offset') or 0
        queryset = services.location_types.find().skip(offset).limit(limit)

        dataset = marshal(list(queryset), LOCATION_TYPE_FIELD_MAPPER)

        for d in dataset:
            urlfield = fields.Url('locations.api.locationtype')
            d['uri'] = urlfield.output('uri', {'loc_type_id': d['id']})

        result = {
            'meta': {
                'limit': limit,
                'offset': offset,
                'total': queryset.count(False)
            },
            'objects': dataset
        }

        return jsonify(result)
Exemple #4
0
    def get(self):
        # marshal() can also handle a list or tuple of objects, but it only
        # checks for a list or tuple, so we need to convert the queryset
        # to a list
        args = parser.parse_args()
        limit = min(
            args.get('limit') or current_app.config.get('PAGE_SIZE'),
            current_app.config.get('PAGE_SIZE'))
        offset = args.get('offset') or 0
        queryset = services.location_types.find().skip(offset).limit(limit)

        dataset = marshal(
            list(queryset),
            LOCATION_TYPE_FIELD_MAPPER
        )

        for d in dataset:
            urlfield = fields.Url('locations.api.locationtype')
            d['uri'] = urlfield.output('uri', {'loc_type_id': d['id']})

        result = {
            'meta': {
                'limit': limit,
                'offset': offset,
                'total': queryset.count(False)
            },
            'objects': dataset
        }

        return jsonify(result)