def create(): if request.method == 'POST': name = request.form['name'] wines = request.form.getlist('wines') allergens = request.form.getlist('allergens') error = None if not name: error = "Entree name is required" if error is not None: flash(error) else: Entree(name=name, wines=wines, allergens=allergens).save() return redirect(url_for('entree.index')) return render_template('entree/create.html')
def get(self): entrees = Entree.objects().to_json() return Response(entrees, mimetype="application/json", status=200)
def delete(self, id): Entree.objects().get(id=id).delete() return '', 200
def put(self, id): body = request.get_json() Entree.objects().get(id=id).update(**body) return '', 200
def get(self, id): entree = Entree.objects().get(id=id).to_json() return Response(entree, mimetype="application/json", status=200)
def post(self): body = request.get_json() entree = Entree(**body).save() id = entree.id return {'id': str(id)}, 200
def get_entree(id): entree = Entree.objects().get(id=id) if entree is None: abort(404, "Entree id {0} doesn't exist.".format(id)) return entree
def index(): entrees = Entree.objects() return render_template('entree/index.html', entrees=entrees)