def create_api_request(rf, method='get', url='/', data='', user=None, encode_as_json=True):
 content_type = 'application/x-www-form-urlencoded'
 if (data and encode_as_json):
  from pootle.core.utils.json import jsonify
  content_type = 'application/json'
  data = jsonify(data)
 request_method = getattr(rf, method.lower())
 request = request_method(url, data=data, content_type=content_type)
 request.META['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'
 if (user is not None):
  request.user = user
 return request

def create_api_request ( rf , method = 'get' , url = '/' , data = '' , user = None , encode_as_json = True ) : content_type = 'application/x-www-form-urlencoded' if ( data and encode_as_json ) : from pootle . core . utils . json import jsonify content_type = 'application/json' data = jsonify ( data ) request_method = getattr ( rf , method . lower ( ) ) request = request_method ( url , data = data , content_type = content_type ) request . META [ 'HTTP_X_REQUESTED_WITH' ] = 'XMLHttpRequest' if ( user is not None ) : request . user = user return request
convenience function to create and setup fake requests .