def __handle_method_field(self, method, args): ''' Handle fields of type str that are instance method ''' result = method( *args ) if is_valuesset( result ): return { method.__name__: list( result ) } elif is_queryset( result ): return { method.__name__: [unicode(i) for i in result] } return { method.__name__: self.__serialize(result) }
def handle_response(self, request, response, fields, parameters): ''' Proccess response into a JSON serializable object ''' current_fields = fields(kwargs) if callable(fields) else fields status = DEFAULT_STATUS_CODE if is_tuple(response): status, response = response if is_valuesset(response): response = self.handle_list_response( request, list(response), current_fields, parameters) elif is_queryset(response): response = self.select_related(response, current_fields) response = self.handle_queryset_response( request, response, current_fields, parameters) elif is_modelinstance(response): response = self.handle_model_response(response, current_fields) elif is_generator(response) or is_list(response): response = self.handle_list_response( request, response, current_fields, parameters) response = self.uglify_json(response) if self.uglify else response return to_http(request, response, status)