def post(self, winery_id): """ >>> v = Winery() >>> key = v.create({'name':'winery'}) >>> ndb.Key.load_get(v ) >>> h = WineryHandler() >>> h.request.POST = {'location':'Canada'} >>> h.post('12345') >>> h.response.content_type 'application/json' >>> h.response.last_write '{..."country": "Canada"...}' >>> h.response.last_write '{..."name": "winery"...}' >>> h.response.last_write '{..."key":...}' """ post = self.request.POST winery_key = ndb.Key(Winery, int(winery_id)) winery = winery_key.get() try: winery.modify(post) wines = Wine.winery_query(winery) winery.update(wines) Event.update(self.request.remote_addr, "Winery", winery_key) except YouNeedATokenForThat as e: self.response.write(str(e)) self.response.status = "401 Unauthorized" return json_response(self, winery)
def post(self, winery_id, wine_id, userwine_id, tasting_id): post = self.request.POST tasting_key = ndb.Key(Winery, int(winery_id), Wine, int(wine_id), UserWine, int(userwine_id), WineTasting, int(tasting_id)) tasting = tasting_key.get() tasting.modify(post) Event.update(self.request.remote_addr, "WineTasting", tasting_key) json_response(self, tasting)
def post(self, cellar_id, winebottle_id=None): if winebottle_id is None: winebottle_id = cellar_id cellar_id = User.get_current_user().cellar.id() bottle_key = ndb.Key(WineCellar, int(cellar_id), WineBottle, int(winebottle_id)) bottle = bottle_key.get() if not bottle: self.response.write("404 Not Found") self.response.status = "404 Not Found" return if not User.has_access(ndb.Key(WineCellar, int(cellar_id))): self.response.write("403 Forbidden") self.response.status = "403 Forbidden" return post = self.request.POST if 'wine_id' in post and 'winery_id' in post: wine_key = ndb.Key(Winery, int(post['winery_id']), Wine, int(post['wine_id'])) wine = wine_key.get() del post['wine_id'] del post['winery_id'] bottle.wine = wine.key key = bottle.modify(post) Event.update(self.request.remote_addr, "WineBottle", key) self.response.content_type = "application/json" json_response(self, bottle) else: json_response(self, { "error": "there was no wine_id", "post": self.request.body })
def post(self, cellar_id): post = self.request.POST cellar_key = ndb.Key(WineCellar, int(cellar_id)) cellar = cellar_key.get() if not cellar: self.response.write("404 Not Found") self.response.status = "404 Not Found" return if not User.has_access(cellar_key): self.response.write("403 Forbidden") self.response.status = "403 Forbidden" return cellar.modify(post) Event.update(self.request.remote_addr, "WineCellar", cellar_key) json_response(self, cellar)
def post(self, winery_id, wine_id, userwine_id): post = self.request.POST userwine_key = ndb.Key(Winery, int(winery_id), Wine, int(wine_id), UserWine, int(userwine_id)) userwine = userwine_key.get() if not userwine: self.response.write("404 Not Found") self.response.status = "404 Not Found" return if userwine.user != User.get_current_user().key: self.response.write("403 Forbidden") self.response.status = "403 Forbidden" return userwine.modify(post) Event.update(self.request.remote_addr, "UserWine", userwine_key) json_response(self, userwine)
def post(self, winery_id, wine_id): winery_key = ndb.Key(Winery, int(winery_id)) winery = winery_key.get() wine_key = ndb.Key(Winery, int(winery_id), Wine, int(wine_id)) wine = wine_key.get() if not winery or not wine: self.response.status = "404 Not Found" self.response.write("404 Not found.") return post = self.request.POST try: wine.modify(post, winery) wine.update(winery) Event.update(self.request.remote_addr, "Wine", wine_key) except YouNeedATokenForThat as e: self.response.write(str(e)) self.response.status = "401 Unauthorized" return json_response(self, wine)