def get_name_by_id(self, id): query = { 'id': int(id) } projection = { 'lname': 1, 'fname': 1, 'sname': 1, } obj = self.get_one(query, projection) return helper.gen_fullname( obj['lname'], obj['fname'], obj['sname'] ).decode('utf-8')
def get_all_short_format(self, query): projection = { 'id': 1, 'lname': 1, 'fname': 1, 'sname': 1, 'idm': 1 } sort = [ {'field': 'lname', 'direction': 1}, {'field': 'fname', 'direction': 1}, {'field': 'sname', 'direction': 1} ] objs = self.cli.find_all(query, projection, {}, sort) result = [] for obj in objs: new_obj = {} new_obj['id'] = obj['id'] new_obj['name'] = '<{}> '.format(obj['idm']) + helper.gen_fullname( obj['lname'], obj['fname'], obj['sname'] ) result.append(new_obj) return result