def createStore(name): check = Store.all().filter("name =", name).get() if check: return "store of that name exists" else: a = Store(name=name) a.put() return a
def _modifyItemPrice(store, name, price): '''create item uses this function if item found''' #so error checking is done by createItem parent = Store.all().filter("name =", store).get() item = Item.all().ancestor(parent.key()).filter("name =", name).get() item.price = price item.put() getInventory(update=True)
def createItem(store, name, price): parent = Store.all().filter("name =", store).get() if not parent: parent = createStore(store) item = Item.all().ancestor(parent.key()).filter("name =", name).get() if item: _modifyItemPrice(store, name, price) logging.info("createItem call resulted in modify item of: " +store+" "+name+" "+str(price)) else: item = Item(parent=parent, name=name,price=price, store=store) item.put() getInventory(update=True) logging.info("item created: " + store+" "+name+" "+str(price))
def createItem(store, name, price): parent = Store.all().filter("name =", store).get() if not parent: parent = createStore(store) item = Item.all().ancestor(parent.key()).filter("name =", name).get() if item: _modifyItemPrice(store, name, price) logging.info("createItem call resulted in modify item of: " + store + " " + name + " " + str(price)) else: item = Item(parent=parent, name=name, price=price, store=store) item.put() getInventory(update=True) logging.info("item created: " + store + " " + name + " " + str(price))
def getInventory(update=False): inventory = memg("_inventory123") if (not inventory) or update: if update: logging.info("update: inventory hits db") else: logging.info("inventory hit db") inventory = {} stores = Store.all() for store in stores: inventory[store.name] = {} items = Item.all().ancestor(store.key()) for item in items: item = item.asDict() inventory[store.name][item["name"]] = item mems("_inventory123", inventory) else: logging.info("inventory hits cache") return inventory