def get(self, uid): """ Send parallel information for given sutta. --- parameters: - in: path name: uid type: string required: true responses: 200: description: Suttaplex list schema: id: suttaplex-parallels type: object properties: first_key: description: "first key is the id of first parallel, second of the second and so on." type: array items: $ref: '#/definitions/Parallel' definitions: Parallel: type object: properties: type: type: string partial: type: boolean to: type: array items: $ref: '#/definitions/Suttaplex-parallel' Suttaplex-parallel: type: object properties: uid: type: string difficulty: required: false type: number original_title: type: string type: type: string translations: type: array items: $ref: '#/definitions/Translation' """ language = request.args.get('language', current_app.config.get('DEFAULT_LANGUAGE')) uid = uid.replace('/', '-').strip('-') uid = f'root/{uid}' db = get_db() results = db.aql.execute(PARALLELS, bind_vars={ 'language': language, 'uid': uid }) data = SortedDict(sort_parallels_key) for result in results: if result['to'].get('uid') == 'orphan': for k in ('original_title', 'translated_title'): result['to'][k] = '' result['to']['acronym'] = result['to']['to'].split('#')[0] _from = result.pop('from') try: data[_from].append(result) except KeyError: data[_from] = [result] result['to']['translations'] = sorted( result['to']['translations'], key=language_sort(result['to']['root_lang'])) for entry in data: data[entry] = sorted(data[entry], key=sort_parallels_type_key) return data, 200
def get(self, uid): """ Send parallel information for given sutta. --- parameters: - in: path name: uid type: string required: true responses: 200: description: Suttaplex list schema: id: suttaplex-parallels type: object properties: first_key: description: "first key is the id of first parallel, second of the second and so on." type: array items: $ref: '#/definitions/Parallel' definitions: Parallel: type object: properties: type: type: string partial: type: boolean to: type: array items: $ref: '#/definitions/Suttaplex-parallel' Suttaplex-parallel: type: object properties: uid: type: string difficulty: required: false type: number original_title: type: string type: type: string translations: type: array items: $ref: '#/definitions/Translation' """ language = request.args.get('language', current_app.config.get('DEFAULT_LANGUAGE')) uid = uid.replace('/', '-').strip('-') uid = f'root/{uid}' db = get_db() results = db.aql.execute(PARALLELS, bind_vars={'language': language, 'uid': uid}) data = SortedDict(sort_parallels_key) for result in results: if result['to'].get('uid') == 'orphan': for k in ('original_title', 'translated_title'): result['to'][k] = '' result['to']['acronym'] = result['to']['to'].split('#')[0] _from = result.pop('from') try: data[_from].append(result) except KeyError: data[_from] = [result] result['to']['translations'] = sorted(result['to']['translations'], key=language_sort(result['to']['root_lang'])) for entry in data: data[entry] = sorted(data[entry], key=sort_parallels_type_key) return data, 200
def get(self, uid): """ Send suttaplex for given uid. It is represented in flat list structure where order matters. [vagga, vagga, text, text] represents: vagga vagga text text --- parameters: - in: path name: uid type: string required: true responses: 200: description: Suttaplex list schema: id: suttaplex-list type: array items: $ref: '#/definitions/Suttaplex' definitions: Suttaplex: type: object properties: uid: type: string blurb: type: string difficulty: required: false type: number original_title: type: string type: type: string translations: type: array items: $ref: '#/definitions/Translation' Translation: type: object properties: author: type: string id: type: string lang: type: string title: type: string """ language = request.args.get('language', current_app.config.get('DEFAULT_LANGUAGE')) uid = uid.replace('/', '-').strip('-') db = get_db() results = db.aql.execute(SUTTAPLEX_LIST, bind_vars={ 'language': language, 'uid': uid }) difficulties = {3: 'advanced', 2: 'intermediate', 1: 'beginner'} data = [] edges = {} for result in results: _from = result.pop('from') if result['difficulty']: result['difficulty'] = { 'name': difficulties[result['difficulty']], 'level': result['difficulty'] } parent = None try: parent = edges[_from] except KeyError: data.append(result) _id = f'root/{result["uid"]}' edges[_id] = result result['translations'] = sorted(result['translations'], key=language_sort( result['root_lang'])) if parent: try: parent['children'].append(result) except KeyError: parent['children'] = [result] recursive_sort(data, 'num') # Sorts data inplace data = flat_tree(data) return data, 200
def get(self, uid): """ Send suttaplex for given uid. It is represented in flat list structure where order matters. [vagga, vagga, text, text] represents: vagga vagga text text --- parameters: - in: path name: uid type: string required: true responses: 200: description: Suttaplex list schema: id: suttaplex-list type: array items: $ref: '#/definitions/Suttaplex' definitions: Suttaplex: type: object properties: uid: type: string blurb: type: string difficulty: required: false type: number original_title: type: string type: type: string translations: type: array items: $ref: '#/definitions/Translation' Translation: type: object properties: author: type: string id: type: string lang: type: string title: type: string """ language = request.args.get('language', current_app.config.get('DEFAULT_LANGUAGE')) uid = uid.replace('/', '-').strip('-') db = get_db() results = db.aql.execute(SUTTAPLEX_LIST, bind_vars={'language': language, 'uid': uid}) difficulties = { 3: 'advanced', 2: 'intermediate', 1: 'beginner' } data = [] edges = {} for result in results: _from = result.pop('from') if result['difficulty']: result['difficulty'] = {'name': difficulties[result['difficulty']], 'level': result['difficulty']} parent = None try: parent = edges[_from] except KeyError: data.append(result) _id = f'root/{result["uid"]}' edges[_id] = result result['translations'] = sorted(result['translations'], key=language_sort(result['root_lang'])) if parent: try: parent['children'].append(result) except KeyError: parent['children'] = [result] recursive_sort(data, 'num') # Sorts data inplace data = flat_tree(data) return data, 200