def process_new_plant():
"""Gets the user input from new plant form and adds to the database"""
# if user did not add image url, get one from flickr
name = request.form.get('name')
image = request.form.get('image')
if not image:
image = get_flickr_image(name)
# gets plant info from angular's data passed in and creates new Plant instance
new_plant = Plant(name=name,
species=request.form.get('species'),
image=image,
water=request.form.get('water'),
sun=request.form.get('sun'),
humidity=request.form.get('humidity'),
temperature=request.form.get('temp'))
# adds plant to the database and saves
db.session.add(new_plant)
db.session.commit()
# returns plant ID to angular's callback
return str(new_plant.plant_id)
评论列表
文章目录