def api_search_posts(fields, term): obj = {} def b64(str_in): return base64.encodebytes(str_in.encode()).decode() def explode(file): if os.path.isfile(file): return [{'token': b64(file), 'path': file}] elif os.path.isdir(file): return [{ 'token': b64(os.path.join(file, _f)), 'path': os.path.join(file, _f) } for _f in os.listdir(file) if os.path.isfile(os.path.join(file, _f))] else: return None for p in manifest.search_posts(fields, term): if p['id'] not in obj: p['files'] = explode(p['file_path']) del p['file_path'] obj[p['id']] = p else: for f in explode(p['file_path']): obj[p['id']]['files'].append(f) # import json # print('Sending file list:', json.dumps(list(obj.values()), indent=4, sort_keys=True, separators=(',', ': '))) return list(obj.values())
def api_search_posts(fields, term): obj = {} def b64(str_in): return base64.encodebytes(str_in.encode()).decode() def explode(file): if os.path.isfile(file): return [{'token': b64(file), 'path': file}] elif os.path.isdir(file): return [{ 'token': b64(os.path.join(file, _f)), 'path': os.path.join(file, _f) } for _f in os.listdir(file) if os.path.isfile(os.path.join(file, _f))] else: return [] for p in manifest.search_posts(fields, term): if p['id'] not in obj: p['files'] = explode(p['file_path']) del p['file_path'] if p['files']: obj[p['id']] = p else: for f in explode(p['file_path']): obj[p['id']]['files'].append(f) return list(obj.values())
def api_search_nested_posts(fields, term): obj = {} for p in manifest.search_posts(fields, term): if p['type'] == 'Submission': p['children'] = [] obj[p['id']] = p else: if p['parent'] in obj: obj[p['parent']]['children'].append(p) else: obj[p['id']] = p return list(obj.values())