当前位置: 首页>>代码示例>>Python>>正文


Python ParsedInstance.query_mongo_minimal方法代码示例

本文整理汇总了Python中onadata.apps.viewer.models.parsed_instance.ParsedInstance.query_mongo_minimal方法的典型用法代码示例。如果您正苦于以下问题:Python ParsedInstance.query_mongo_minimal方法的具体用法?Python ParsedInstance.query_mongo_minimal怎么用?Python ParsedInstance.query_mongo_minimal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在onadata.apps.viewer.models.parsed_instance.ParsedInstance的用法示例。


在下文中一共展示了ParsedInstance.query_mongo_minimal方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: to_representation

# 需要导入模块: from onadata.apps.viewer.models.parsed_instance import ParsedInstance [as 别名]
# 或者: from onadata.apps.viewer.models.parsed_instance.ParsedInstance import query_mongo_minimal [as 别名]
    def to_representation(self, obj):
        request = self.context.get('request')

        if not isinstance(obj, XForm):
            return super(DataListSerializer, self).to_representation(obj)

        query_params = (request and request.query_params) or {}
        query = {
            ParsedInstance.USERFORM_ID:
            u'%s_%s' % (obj.user.username, obj.id_string)
        }

        try:
            query.update(json.loads(query_params.get('query', '{}')))
        except ValueError:
            raise ParseError(_("Invalid query: %(query)s"
                             % {'query': query_params.get('query')}))

        query_kwargs = {
            'query': json.dumps(query),
            'fields': query_params.get('fields'),
            'sort': query_params.get('sort')
        }
        cursor = ParsedInstance.query_mongo_minimal(**query_kwargs)
        return list(cursor)
开发者ID:Azique,项目名称:kobocat,代码行数:27,代码来源:data_serializer.py

示例2: to_native

# 需要导入模块: from onadata.apps.viewer.models.parsed_instance import ParsedInstance [as 别名]
# 或者: from onadata.apps.viewer.models.parsed_instance.ParsedInstance import query_mongo_minimal [as 别名]
    def to_native(self, obj):
        request = self.context.get('request')

        if obj is None:
            return super(DataListSerializer, self).to_native(obj)

        query_params = (request and request.QUERY_PARAMS) or {}
        query = {
            ParsedInstance.USERFORM_ID:
            u'%s_%s' % (obj.user.username, obj.id_string)
        }

        try:
            query.update(json.loads(query_params.get('query', '{}')))
        except ValueError:
            raise ParseError(_("Invalid query: %(query)s"
                             % {'query': query_params.get('query')}))

        query_kwargs = {
            'query': json.dumps(query),
            'fields': query_params.get('fields'),
            'sort': query_params.get('sort')
        }
        cursor = ParsedInstance.query_mongo_minimal(**query_kwargs)
        records = list(record for record in cursor)

        return records
开发者ID:199212151746,项目名称:onadata,代码行数:29,代码来源:data_serializer.py

示例3: to_native

# 需要导入模块: from onadata.apps.viewer.models.parsed_instance import ParsedInstance [as 别名]
# 或者: from onadata.apps.viewer.models.parsed_instance.ParsedInstance import query_mongo_minimal [as 别名]
    def to_native(self, obj):
        request = self.context.get('request')
        query_params = (request and request.QUERY_PARAMS) or {}
        query = {
            ParsedInstance.USERFORM_ID:
            u'%s_%s' % (obj.xform.user.username, obj.xform.id_string),
            u'_id': obj.pk
        }
        query_kwargs = {
            'query': json.dumps(query),
            'fields': query_params.get('fields'),
            'sort': query_params.get('sort')
        }
        cursor = ParsedInstance.query_mongo_minimal(**query_kwargs)
        records = list(record for record in cursor)

        return (len(records) and records[0]) or records
开发者ID:iMMAP,项目名称:onadata,代码行数:19,代码来源:data_serializer.py

示例4: to_representation

# 需要导入模块: from onadata.apps.viewer.models.parsed_instance import ParsedInstance [as 别名]
# 或者: from onadata.apps.viewer.models.parsed_instance.ParsedInstance import query_mongo_minimal [as 别名]
    def to_representation(self, obj):
        request = self.context.get('request')

        if not isinstance(obj, XForm):
            return super(DataListSerializer, self).to_representation(obj)

        query_params = (request and request.query_params) or {}
        query = {
            ParsedInstance.USERFORM_ID:
            u'%s_%s' % (obj.user.username, obj.id_string)
        }
        limit = query_params.get('limit', False)
        start = query_params.get('start', False)
        count = query_params.get('count', False)

        try:
            query.update(json.loads(query_params.get('query', '{}')))
        except ValueError:
            raise ParseError(_("Invalid query: %(query)s"
                             % {'query': query_params.get('query')}))

        query_kwargs = {
            'query': json.dumps(query),
            'fields': query_params.get('fields'),
            'sort': query_params.get('sort')
        }

        # if we want the count, we don't kwow to paginate the records.
        # start and limit are useless then.
        if count:
            query_kwargs['count'] = True
        else:
            if limit:
                query_kwargs['limit'] = int(limit)

            if start:
                query_kwargs['start'] = int(start)

        cursor = ParsedInstance.query_mongo_minimal(**query_kwargs)

        # if we want the count, we only need the first index of the list.
        if count:
            return cursor[0]
        else:
            return [MongoHelper.to_readable_dict(record) for record in cursor]
开发者ID:kimetrica,项目名称:kobocat,代码行数:47,代码来源:data_serializer.py


注:本文中的onadata.apps.viewer.models.parsed_instance.ParsedInstance.query_mongo_minimal方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。