コード例 #1
0
def new_restaurant():
    if request.method == 'POST':
        restaurant_name = request.form['restaurant_name']
        Restaurant.create(restaurant_name)
        flash('New restaurant created')
        return redirect(url_for('all_restaurants'))
    else:
        return render_template('new-restaurant.html')
コード例 #2
0
ファイル: app.py プロジェクト: robee/Connoisseur
    def post(self):
        auth_code = self.request.get("auth_code")
        if auth_code != PASSCODE and AUTH_ENABLED:
            self.response.out.write("AUTH FAILED")
            return

        rest = Restaurant.create(self.request.get("name"))
        return_obj = {"secret_key": rest.secret_key, "restaurant_id": rest.restaurant_id}

        menu = Menu.create("menu", rest)
        uiProfile = UIProfile.create(menu)
        menu_item_1 = MenuItem.create("Starter Item 1", menu, 10.00, "Appy", "This is a sample menu Item")
        menu_item_2 = MenuItem.create("Starter Item 2", menu, 11.00, "Drink", "This is a sample menu Item")

        self.response.headers["Access-Control-Allow-Origin"] = "*"
        self.response.out.write(json.dumps(return_obj))
コード例 #3
0
def restaurant(restaurant_id=None):
    app.logger.debug('Args: {}'.format(request.args))
    restaurant_name = to_string(request.args.get('name', ''))
    category = to_string(request.args.get('category', ''))
    if request.method == 'POST':
        if not restaurant_name or not category:
            return json_response(
                {'response': 'Either name or category is missing in params'},
                400)
        result = Restaurant.create(restaurant_name, category)
        return json_response({'response': 'Created', 'id': result.id})
    elif request.method == 'PUT':
        # restaurant_id = int(request.args.get('id', ''))
        app.logger.debug('Restaurant_id: {}'.format(restaurant_id))
        if not restaurant_name and not category:
            json_response(
                {'response': 'Either name or category is missing in params'},
                400)
        result = Restaurant.update(restaurant_id, restaurant_name, category)
        app.logger.debug('result: {}'.format(result))
        return json_response({'response': 'Updated', 'id': result.id})
    else:
        return json_response({'response': 'BAD Request'}, 400)