def SearchDataAdapter(results, format, collection):
 if (results and results['response'] and results['response']['docs']):
  search_data = results['response']['docs']
  if collection['template']['fieldsSelected']:
   headers = collection['template']['fieldsSelected']
  else:
   headers = [field['name'] for field in collection['fields']]
  rows = []
  for data in search_data:
   row = []
   for column in headers:
    if (column not in data):
     row.append('')
    elif (isinstance(data[column], basestring) or isinstance(data[column], (int, long, float, complex))):
     row.append(data[column])
    elif isinstance(data[column], list):
     row.append([smart_str(val, errors='replace') for val in data[column]])
    else:
     row.append(smart_str(data[column]))
   rows.append(row)
 else:
  rows = [[]]
 (yield (headers, rows))

def SearchDataAdapter ( results , format , collection ) : if ( results and results [ 'response' ] and results [ 'response' ] [ 'docs' ] ) : search_data = results [ 'response' ] [ 'docs' ] if collection [ 'template' ] [ 'fieldsSelected' ] : headers = collection [ 'template' ] [ 'fieldsSelected' ] else : headers = [ field [ 'name' ] for field in collection [ 'fields' ] ] rows = [ ] for data in search_data : row = [ ] for column in headers : if ( column not in data ) : row . append ( '' ) elif ( isinstance ( data [ column ] , basestring ) or isinstance ( data [ column ] , ( int , long , float , complex ) ) ) : row . append ( data [ column ] ) elif isinstance ( data [ column ] , list ) : row . append ( [ smart_str ( val , errors = 'replace' ) for val in data [ column ] ] ) else : row . append ( smart_str ( data [ column ] ) ) rows . append ( row ) else : rows = [ [ ] ] ( yield ( headers , rows ) )
searchdataadapter -> headers .