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
评论列表
文章目录