def create_restaurant(): # create new restaurant body = request.json name = body['name'] if name is None or name == "": raise ApiError(u"Введите название ресторана.") rest = Restaurant() rest.name = name rest.user_id = current_user.id created_rest = Restaurant.get_by_name(rest.name) if created_rest is not None: raise ApiError(u"Ресторан с данным именем уже существует.") location = body.get('location') if location is not None: rest.latitude = location.get('longitude') rest.latitude = location.get('latitude') session.add(rest) session.commit() return jsonify(rest.serialize)
def newRestaurant(): if not isSigned(): return redirect('/login') if request.method == 'POST': dbSession = LocalUserManager(session) dbUserId = dbSession.getUserId(login_session['email']) newRestaurant = Restaurant(name = request.form['name']) newRestaurant.user_id = dbUserId session.add(newRestaurant) flash('New Restaurant %s Successfully Created' % newRestaurant.name) session.commit() return redirect(url_for('showRestaurants')) else: return render_template('newRestaurant.html')
def createRestaurant(): context = {"user_id": login_session["user_id"]} if request.method == "POST": new_restaurant = Restaurant(name=request.form["restaurant-name"]) new_restaurant.user_id = login_session["user_id"] try: session.add(new_restaurant) session.commit() message = "New Restaurant %s Successfully Created" % new_restaurant.name flash(message, "info") except: message = "There is an error adding this item" flash(message, "error") return redirect(url_for("newMenuItem", restaurant_id=new_restaurant.id)) else: return render_template("newRestaurant.html", context=context)