def editRestaurant(restaurant_id): if request.method == 'POST': restaurant_dao.updateRestaurant(restaurant_id, request.form['name']) flash("Edited restaurant!") return redirect(url_for('restaurantMenus')) else: restaurant = restaurant_dao.getRestaurant(restaurant_id) return render_template('edit-restaurant.html', restaurant=restaurant)
def do_POST(self): try: ctype, pdict = cgi.parse_header(self.headers.getheader('content-type')) self.send_response(301) self.send_header('Location','/restaurants') self.end_headers() if ctype == 'multipart/form-data': fields = cgi.parse_multipart(self.rfile, pdict) if self.path.endswith("/restaurants/new"): name = fields.get('name')[0] restaurant_dao.addRestaurant(name) return elif self.path.endswith("/edit"): id = self.path.split("/")[2] name = fields.get('name')[0] restaurant_dao.updateRestaurant(id, name) return elif self.path.endswith("/delete"): id = self.path.split("/")[2] restaurant_dao.deleteRestaurant(id) return except: pass