Пример #1
0
def add_category(restaurant_id):

    restaurant = Restaurant.get_by_id(restaurant_id)
    if restaurant is None:
        raise ApiError("Restaurant not exist")

    #if restaurant.user_id != current_user.id:
    #    raise ApiError("you have not access to this restaurant")

    category = Category()
    name = request.json.get('name')

    if not name:
        raise ApiError(u"Введите имя")

    category.name = name

    category.restaurant_id = restaurant_id

    session.add(category)
    session.commit()

    template_dict = request.json.get('template')

    if template_dict is not None:
        add_template_dict_for_category(template_dict, category)

    return jsonify(category.serialize)
Пример #2
0
def restaurant(restaurant_id):

    rest = Restaurant.get_by_id(restaurant_id)
    if rest is None:
        raise ApiError("Restaurant is not exist")

    if request.method == "GET":
        return jsonify(rest.full_serialize)
    else:
        session.delete(rest)
        session.commit()
        return jsonify(success=True)
Пример #3
0
def available_users(rest_id):
    restaurant = Restaurant.get_by_id(rest_id)
    edit_users = restaurant.edit_users
    current_id = current_user.id

    edit_users_ids = []
    for user in edit_users:
        edit_users_ids.append(user.id)

    users = session.query(User).filter(User.id != current_id)
    result = []
    for user in users:
        if user.id not in edit_users_ids:
            result.append(user)

    return jsonify([user.serialize for user in result])
Пример #4
0
def change_edit_user(rest_id, user_id):
    restaurant = Restaurant.get_by_id(rest_id)

    if restaurant.user_id != current_user.id:
        raise ApiError("Меню " + restaurant.name +
                       " не принадлежит данному пользователю!")

    user = User.get_by_id(user_id)

    add_access = request.method == 'POST'
    if add_access:
        restaurant.edit_users.append(user)
    else:
        restaurant.edit_users.remove(user)

    notify_user(user, current_user, restaurant, add_access)

    session.add(restaurant)
    session.add(user)
    session.commit()

    return jsonify([user.serialize for user in restaurant.edit_users])