def req_factory_factory(url='', user=None, post=False, data=None, **kwargs):
 req = RequestFactory()
 if post:
  req = req.post(url, (data or {}))
 else:
  req = req.get(url, (data or {}))
 if user:
  req.user = UserProfile.objects.get(id=user.id)
  req.groups = user.groups.all()
 else:
  req.user = AnonymousUser()
 req.check_ownership = partial(check_ownership, req)
 req.REGION = kwargs.pop('region', mkt.regions.REGIONS_CHOICES[0][1])
 req.API_VERSION = 2
 for key in kwargs:
  setattr(req, key, kwargs[key])
 return req

def req_factory_factory ( url = '' , user = None , post = False , data = None , ** kwargs ) : req = RequestFactory ( ) if post : req = req . post ( url , ( data or { } ) ) else : req = req . get ( url , ( data or { } ) ) if user : req . user = UserProfile . objects . get ( id = user . id ) req . groups = user . groups . all ( ) else : req . user = AnonymousUser ( ) req . check_ownership = partial ( check_ownership , req ) req . REGION = kwargs . pop ( 'region' , mkt . regions . REGIONS_CHOICES [ 0 ] [ 1 ] ) req . API_VERSION = 2 for key in kwargs : setattr ( req , key , kwargs [ key ] ) return req
creates a request factory .