def dump_app(id, **kw): from mkt.webapps.api import AppSerializer # Because @robhudson told me to. # Note: not using storage because all these operations should be local. target_dir = os.path.join(settings.DUMPED_APPS_PATH, 'apps', str(id / 1000)) target_file = os.path.join(target_dir, str(id) + '.json') try: obj = Webapp.objects.get(pk=id) except Webapp.DoesNotExist: task_log.info(u'Webapp does not exist: {0}'.format(id)) return req = RequestFactory().get('/') req.user = AnonymousUser() req.REGION = RESTOFWORLD if not os.path.exists(target_dir): os.makedirs(target_dir) task_log.info('Dumping app {0} to {1}'.format(id, target_file)) res = AppSerializer(obj, context={'request': req}).data json.dump(res, open(target_file, 'w'), cls=JSONEncoder) return target_file
def dump_app(id, **kw): # Because @robhudson told me to. from mkt.api.resources import AppResource # Note: not using storage because all these operations should be local. target_dir = os.path.join(settings.DUMPED_APPS_PATH, 'apps', str(id / 1000)) target_file = os.path.join(target_dir, str(id) + '.json') try: obj = Webapp.objects.get(pk=id) except Webapp.DoesNotExist: task_log.info(u'Webapp does not exist: {0}'.format(id)) return req = RequestFactory().get('/') req.user = AnonymousUser() req.REGION = WORLDWIDE if not os.path.exists(target_dir): os.makedirs(target_dir) task_log.info('Dumping app {0} to {1}'.format(id, target_file)) res = AppResource().dehydrate_objects([obj], request=req) json.dump(res[0], open(target_file, 'w'), cls=JSONEncoder) return target_file
def get_request(self, data=None): if data is None: data = {} request = RequestFactory().get("/", data) request.REGION = mkt.regions.RESTOFWORLD request.API = True return request
def get_request(self, data=None): if data is None: data = {} request = RequestFactory().get('/', data) request.REGION = mkt.regions.RESTOFWORLD request.API = True return request
def req_factory_factory(url='', user=None, post=False, data=None, **kwargs): """Creates a request factory, logged in with the user.""" 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 get_request(self, query_string): request = RequestFactory().get('/', query_string) request.REGION = mkt.regions.WORLDWIDE request.API = True return request
def collection_data(collection): request = RequestFactory().get("/") request.user = AnonymousUser() request.REGION = RESTOFWORLD return ShortAppsCollectionSerializer(collection, context={"request": request}).data
def collection_data(collection): request = RequestFactory().get('/') request.user = AnonymousUser() request.REGION = RESTOFWORLD return ShortAppsCollectionSerializer(collection, context={'request': request}).data