示例#1
0
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')
示例#2
0
 def get(self):
     entrees = Entree.objects().to_json()
     return Response(entrees, mimetype="application/json", status=200)
示例#3
0
 def delete(self, id):
     Entree.objects().get(id=id).delete()
     return '', 200
示例#4
0
 def put(self, id):
     body = request.get_json()
     Entree.objects().get(id=id).update(**body)
     return '', 200
示例#5
0
 def get(self, id):
     entree = Entree.objects().get(id=id).to_json()
     return Response(entree, mimetype="application/json", status=200)
示例#6
0
 def post(self):
     body = request.get_json()
     entree = Entree(**body).save()
     id = entree.id
     return {'id': str(id)}, 200
示例#7
0
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
示例#8
0
def index():
    entrees = Entree.objects()
    return render_template('entree/index.html', entrees=entrees)