def from_csv(self, content, root='objects', **kwargs): ''' @param root - property to nest the return object iterable in for the response (None if no nesting, and return object will be an iterable) ''' if isinstance(content, six.binary_type): content = force_text(content) objects = csvutils.from_csv( cStringIO.StringIO(content), list_delimiter=LIST_DELIMITER_CSV, list_keys=kwargs.get('list_keys', None)) if root: return { root: objects } else: return objects
def from_csv(self, content, root='objects', list_keys=None, list_delimiters=None, **kwargs): ''' @param root - property to nest the return object iterable in for the response (None if no nesting, and return object will be an iterable) ''' if isinstance(content, six.binary_type): content = force_text(content) data = csvutils.from_csv( StringIO.StringIO(content), # Note: do not use cStringIO here, because Unicode data will be read # cStringIO.StringIO(content), list_keys=list_keys, list_delimiters=list_delimiters) if root: return { root: data } else: return data
def from_csv(self, content, root='objects', list_keys=None, list_delimiters=None, **kwargs): ''' @param root - property to nest the return object iterable in for the response (None if no nesting, and return object will be an iterable) ''' if isinstance(content, six.binary_type): content = force_text(content) data = csvutils.from_csv( StringIO.StringIO(content), # Note: do not use cStringIO here, because Unicode data will be read # cStringIO.StringIO(content), list_keys=list_keys, list_delimiters=list_delimiters) if root: return {root: data} else: return data
password = args.password if not password: password = getpass.getpass() headers = {} #### log in using django form-based auth, and keep the session session = get_logged_in_session(args.username, password, base_url) # django session based auth requires a csrf token headers['X-CSRFToken'] = session.cookies['csrftoken'] # always accept json for debugging the returned values headers['Accept'] = 'application/json' with open(args.input_actions_file) as input_file: api_init_actions = csvutils.from_csv(input_file) for action in api_init_actions: print '\n++++=========== processing action', json.dumps(action) command = action['command'].lower() resource = action['resource'].lower() resource_uri = url + '/' + resource # tastypie session based auth requires the referer to be set headers['Referer'] = resource_uri if command == 'delete': headers.update(CONTENT_TYPES['json']) delete(resource_uri, headers, session=session)
password = args.password if not password: password = getpass.getpass() session_headers ={} logger.info('begin processing file: %r', args.input_actions_file) session = django_requests.get_logged_in_session( username, password, base_url) # Django session based auth requires a csrf token session_headers['X-CSRFToken'] = session.cookies['csrftoken'] # Always accept json for debugging the returned values session_headers['Accept'] = 'application/json' with open(args.input_actions_file) as input_file: api_init_actions = csvutils.from_csv(input_file) for action in api_init_actions: print '\n++++=========== processing action', json.dumps(action) command = action['command'].lower() resource = action['resource'].lower() resource_uri = url + '/' + resource headers = session_headers.copy() headers['Referer']=resource_uri if command == 'delete': delete(resource_uri, headers, session=session) else: data_file = os.path.join(args.input_dir,action['file'])