def delete(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 bottle.delete() Event.create(self.request.remote_addr, "WineBottle", bottle_key) json_response(self, {"success": True})
def get(self, cellar_id): 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 json_response(self, cellar)
def get(self): cellar_key = User.get_current_user().cellar if cellar_key is None: return json_response(self, []) 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 json_response(self, cellar)
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 get(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 json_response(self, bottle)
def get(self, cellar_id=None): if cellar_id is None: cellar_id = User.get_current_user().cellar.id() 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 qry = WineBottle.query(ancestor=cellar.key) results = qry.fetch(MAX_RESULTS) json_response(self, results)
def delete(self, cellar_id): 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 qry = WineBottle.query(ancestor=cellar.key) results = qry.fetch(MAX_RESULTS) for bottle in results: bottle.delete() cellar.delete() user = User.get_current_user() user.cellar = None user.put() Event.delete(self.request.remote_addr, "WineCellar", cellar_key) json_response(self, {"success": True})