def save_resource(resource_type, resource_data): ''' save a resource to database and index its elements by search params ''' if 'meta' in resource_data: print resource_data['meta'] #del resource_data['meta'] try: del resource_data['privacy_policy'] except: pass valid, search_elements = parse_resource(resource_type, resource_data) assert valid if 'id' in resource_data: resource = test_resource(resource_type, resource_data, resource_id=resource_data['id']) else: resource = test_resource(resource_type, resource_data) index_resource(resource, search_elements, g=BUF) output = json.loads(resource.data) if 'id' not in resource_data: resource_data['id'] = output['id'] #print resource_data if WRITE_TO_FILE: with open( 'STU_3_static_example/{}_{}.json'.format( resource_type, resource_data['id']), 'w') as spec_target: spec_target.write(json.dumps(resource_data, indent=4)) return resource
def save_resource(resource_type, resource_data): ''' save a resource to database and index its elements by search params ''' valid, search_elements = parse_resource(resource_type, resource_data) assert valid resource = test_resource(resource_type, resource_data) index_resource(resource, search_elements, g=BUF) return resource