def redbook_filter(request): dbsession = DBSession() query_str = request.params['name'].encode('utf-8').decode('utf-8') start = int(request.params['start']) count = int(request.params['count']) try: query_str_upper = query_str.upper() aFilter = u"UPPER({0}) LIKE '%{1}%'".format('name', query_str_upper) order_by_clauses = [] order_by_clauses = dojo.parse_sort(request) red_books = dbsession.query(RedBook.id, RedBook.name)\ .filter(aFilter)\ .order_by(order_by_clauses)\ .all() itemsPage = red_books[start:start + count] except DBAPIError: return {'success': False, 'msg': 'Ошибка подключения к БД'} rows = [{'id': id, 'name': name} for id, name in itemsPage] dbsession.close() return {'items': rows, 'success': True, 'numRows': len(itemsPage), 'identity': 'id'}
def redbook_filter(request): dbsession = DBSession() query_str = request.params['name'].encode('utf-8').decode('utf-8') start = int(request.params['start']) count = int(request.params['count']) try: query_str_upper = query_str.upper() aFilter = u"UPPER({0}) LIKE '%{1}%'".format('name', query_str_upper) order_by_clauses = [] order_by_clauses = dojo.parse_sort(request) red_books = dbsession.query(RedBook.id, RedBook.name)\ .filter(aFilter)\ .order_by(order_by_clauses)\ .all() itemsPage = red_books[start:start + count] except DBAPIError: return {'success': False, 'msg': 'Ошибка подключения к БД'} rows = [{'id': id, 'name': name} for id, name in itemsPage] dbsession.close() return { 'items': rows, 'success': True, 'numRows': len(itemsPage), 'identity': 'id' }
def species_by_redbook(request): dbsession = DBSession() redbook_id = request.matchdict['redbook_id'] order_by_clauses = dojo.parse_sort(request) species = dbsession.query(Taxon, RedBookSpecies) \ .join(RedBookSpecies, Taxon.id == RedBookSpecies.specie_id) \ .filter(RedBookSpecies.red_book_id == redbook_id) \ .order_by(order_by_clauses) \ .all() rows = [dict(specie[0].as_json_dict().items() + specie[1].as_json_dict().items()) for specie in species] dbsession.close() return rows
def species_by_redbook(request): dbsession = DBSession() redbook_id = request.matchdict['redbook_id'] order_by_clauses = dojo.parse_sort(request) species = dbsession.query(Taxon, RedBookSpecies) \ .join(RedBookSpecies, Taxon.id == RedBookSpecies.specie_id) \ .filter(RedBookSpecies.red_book_id == redbook_id) \ .order_by(order_by_clauses) \ .all() rows = [ dict(specie[0].as_json_dict().items() + specie[1].as_json_dict().items()) for specie in species ] dbsession.close() return rows