Exemplo n.º 1
0
    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))
Exemplo n.º 2
0
def ModelsFromDoc(jsonString, rest_id):
    try:
        obj = json.loads(jsonString)

        profile_id = obj["ui_profile"]["profile_id"]

        # Create or Update Rest
        rest = Restaurant.get_by_id(rest_id)
        rest.name = obj["restaurant_name"]

        # Create or Update Menu
        menu = Menu.get_menus_by_rest_id(rest_id)[0]

        menu.name = obj["menu_name"]
        menu.resturant = rest

        # Create or Update UI Profile
        UIProfile.delete_by_menu(menu)
        ui_profile = UIProfile.create(menu)
        ui_profile.template = obj["ui_profile"]["template"]
        ui_profile.color = obj["ui_profile"]["color"]
        ui_profile.font = obj["ui_profile"]["font"]
        ui_profile.logo_url = obj["ui_profile"]["logo_url"]
        # logging.info(str(obj))
        # Create or Update menuitems

        MenuItem.delete_by_menu(menu)
        menu_items_dict = obj["menuitems"]
        logging.info(type(menu_items_dict))
        for category in menu_items_dict.keys():
            category_list = menu_items_dict[category]
            for menu_item_dict in category_list:
                menuitem = MenuItem.create(
                    menu_item_dict["name"],
                    menu,
                    menu_item_dict["price"],
                    category,
                    menu_item_dict["image"],
                    menu_item_dict["description"],
                )
                menuitem.put()
        ui_profile.put()
        menu.put()
        rest.put()
        return True
    except:
        return False
Exemplo n.º 3
0
    def post(self):
        if AUTH_ENABLED and not verifyMessage(self.request):
            self.response.out.write("AUTH FAILED")
            return
        rest_id = self.request.get("restaurant_id")
        menu_name = self.request.get("menu_name")

        rest = Restaurant.get_by_id(rest_id)
        if not rest:
            self.response.out.write("Invalid restaurant_id")
            return

        if Menu.get_menus_by_rest_id(rest_id):
            self.resonse.out.write("Cant create another menu for this restaurant.  It already has one")
            return

        menu = Menu.create(menu_name, 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.add_header("Access-Control-Allow-Origin", "*")
        self.response.headers.add_header("Access-Control-Allow-Headers", "X-Requested-With")
        self.response.out.write(DocFromModels(rest_id, menu.menu_id))