Beispiel #1
0
def restaurant_add_update_category():
    user = get_user()

    if (user):
        restaurant = Restaurant.get_from_id(user.restaurant_id)

        if (restaurant):
            name = get_header("name")
            id = get_header_int("id")

            if (name and len(name) <= 50):
                if (is_int(id)):
                    category = Category.get_from_id(restaurant, id)

                    if (category):
                        if (get_header("remove")):
                            category.remove()
                        else:
                            category.name = name
                            get_session().commit()

                        return "true"
                    else:
                        abort(404)
                else:
                    Category.add(name, restaurant)

                    return "true"
            else:
                abort(400)

        else:
            abort(404)
    else:
        abort(404)
Beispiel #2
0
def add():
    cat = Category()
    id = randint(0, 999999)
    name = request.form.get("name")
    ret = cat.add((id, name))
    if ret > 0:
        return jsonify({"id": id, "name": name})
    return "Failed"
Beispiel #3
0
    def post(self, *args, **kwargs):
        """新建"""
        category_name = self.get_angular_argument('name')

        if not category_name:
            self.on_error(**ErrorCodeMessage.category_name_illegal)
            return

        category = Category.add(category_name)

        if not category:
            self.on_error(**ErrorCodeMessage.database_error)
            return

        self.on_success(category.to_dict())
Beispiel #4
0
def first_run():
    from models.client import Client
    from models.category import Category
    from models.orders import Order
    from models.product import Product
    from models.restaurants import Restaurant
    from models.user import User
    meta = sqlalchemy.MetaData(engine)
    meta.reflect()
    #meta.drop_all()

    print("First run, please wait while the db is being populated...")

    # Create tables
    Base.metadata.create_all(engine)

    testClient = Client.add("6977988551")
    testClient2 = Client.add("8891155521")

    restaurant = Restaurant.add(
        "Restaurant 1",
        "The best food you'll find in the city\nWe make sandwiches, salads and burgers"
    )

    sandwichesCategory = Category.add("Sandwiches", restaurant)
    Product.add("Pulled Pork", "With tangy barbecue sauce on an onion knot",
                9.50, restaurant, sandwichesCategory)
    Product.add(
        "Turkey Club",
        "Roasted turkey breast, bacon, lettuce, avocado and tomato on baguette",
        8, restaurant, sandwichesCategory)
    Product.add(
        "Reuben",
        "Corned beef, melted swiss, sauerkraut and thousand island on marbled rye",
        8, restaurant, sandwichesCategory)
    Product.add(
        "Shrimp Cilantro Wrap",
        "Shrimp, avocado, mixed greens, salsa, cilantro and may on a tomato tortilla",
        8.5, restaurant, sandwichesCategory)

    burgerCategory = Category.add("Burgers", restaurant)
    Product.add(
        "Grass-fed Beef Burger",
        "With sharp cheddar, heirloom tomatoes and caramelized onions", 9.5,
        restaurant, burgerCategory)
    Product.add(
        "Mushroom Swiss Burger",
        "With sautéed mushrooms and melted swiss on a home-baked roll", 10,
        restaurant, burgerCategory)
    Product.add(
        "Hickory Burger",
        "Topped with cheddar, hickory smoked bacon and smoked barbecue sauce",
        10, restaurant, burgerCategory)
    Product.add(
        "Chicken Burger",
        "Grilled chicken breast with heirloom tomatoes, avocado and sprouts on a home-baked roll",
        9, restaurant, burgerCategory)

    saladCategory = Category.add("Salads", restaurant)
    Product.add(
        "Caesar Salad",
        "Romaine, fresh parmesan, seasoned croutons and black pepper with garlic anchovy dressing",
        6.75, restaurant, saladCategory)
    Product.add("Red Iceberg Salad",
                "With sweet corn, blackberries, goat cheese and fresh basil",
                9.25, restaurant, saladCategory)
    Product.add(
        "House Salad",
        "With green olives, green peppers, onions, cucumbers, and tomato",
        6.75, restaurant, saladCategory)
    Product.add(
        "Blue Chicken Salad",
        "Mesclun greens, apple, grilled chicken, gorgonzola, chesse and balsamic vinagrette",
        9.25, restaurant, saladCategory)

    # Add an user for the restaurant we just created
    User.add("restaurant1", "restaurant1", 0, restaurant)

    streets = [
        "Oak Street", "Madison Avenue", "Bridle Lane", "Jefferson Street",
        "Lafayette Avenue", "Grove Street", "Chestnut Avenue"
    ]

    # Simulate some orders on a different client
    originalDate = time.time() - 57600000
    for i in range(87):
        productCount = randint(1, 2)
        used = {}
        products = []
        price = 0

        originalDate += randint(376000, 576000)

        for y in range(productCount):
            id = randint(0, 11)
            while (id in used):
                id = randint(0, 11)

            used[id] = True
            amount = randint(1, 2)
            products.append({"id": id + 1, "count": amount})
            product = Product.get_from_id(id + 1)
            price += amount * product.price

        order = Order.add(
            random.choice(streets) + " " + str(randint(1, 5000)), price, "",
            products, [-34.601874, -58.432611], testClient2, restaurant)
        order.date = originalDate
        order.status = 2
        get_session().commit()

    Order.add("Bridle Lane 1775", 9.50, "", [{
        'id': 1,
        'count': 1
    }], [-34.601874, -58.432611], testClient, restaurant)