def search_food(local, name): # local = request.args.get('local', 'en', type=str) # name = request.args.get('name', type=str) page = request.args.get('page', 1, type=int) per_page = min(request.args.get('per_page', 10, type=int), 100) if local not in ['fr', 'en']: return bad_request('Wrong local, fr|en') attrib = Food.name_en if local == 'en' else Food.name_fr data = Food.to_collection_dict( Food.query.filter(attrib.like('%{}%'.format(name))), page, per_page, 'api.search_food', local=local, name=name ) return jsonify(data)
def get_foods(): page = request.args.get('page', 1, type=int) per_page = min(request.args.get('per_page', 10, type=int), 100) data = Food.to_collection_dict(Food.query, page, per_page, 'api.get_foods') return jsonify(data)