stats_serializer.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:FormShare 作者: qlands 项目源码 文件源码
def to_native(self, obj):
        if obj is None:
            return super(StatsInstanceSerializer, self).to_native(obj)

        request = self.context.get('request')
        method = request.QUERY_PARAMS.get('method', None)
        field = request.QUERY_PARAMS.get('field', None)

        if field and field not in obj.data_dictionary().get_keys():
            raise exceptions.ParseError(detail=_("Field not in XForm."))

        stats_function = STATS_FUNCTIONS.get(method and method.lower(),
                                             get_all_stats)

        try:
            data = stats_function(obj, field)
        except ValueError as e:
            raise exceptions.ParseError(detail=e.message)

        return data
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号