コード例 #1
0
    def post(self):
        post = self.request.POST

        cellar = WineCellar()
        try:
            user = User.get_current_user()
            if user.cellar is not None:
                self.response.write("403 Forbidden - User already has cellar")
                self.response.status = "403 Forbidden"
                return
            key = cellar.create(post)

            user.cellar = key
            user.put()

            # refresh the user cache
            user = User.get_current_user()
            if not user.has_access(key):
                print "see? do you SEE what I put up with?"

            Event.create(self.request.remote_addr, "WineCellar", key)
        except ValueError as e:
            self.response.status = "400 Bad Request"
            self.response.write(str(e))
            return

        json_response(self, cellar)
コード例 #2
0
    def post(self):
        post = self.request.POST

        cellar = WineCellar()
        try:
            user = User.get_current_user()
            if user.cellar is not None:
                self.response.write("403 Forbidden - User already has cellar")
                self.response.status = "403 Forbidden"
                return
            key = cellar.create(post)

            user.cellar = key
            user.put()

            # refresh the user cache
            user = User.get_current_user()
            if not user.has_access(key):
                print "see? do you SEE what I put up with?"

            Event.create(self.request.remote_addr, "WineCellar", key)
        except ValueError as e:
            self.response.status = "400 Bad Request"
            self.response.write(str(e))
            return

        json_response(self, cellar)
コード例 #3
0
    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})
コード例 #4
0
    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)
コード例 #5
0
    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)
コード例 #6
0
    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
            })
コード例 #7
0
    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)
コード例 #8
0
    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)
コード例 #9
0
    def delete(self, winery_id, wine_id, userwine_id):
        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.delete()
        json_response(self, {"success": True})
コード例 #10
0
    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})
コード例 #11
0
    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)
コード例 #12
0
    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})
コード例 #13
0
    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)
コード例 #14
0
    def post(self, winery_id, wine_id):
        wine_key = ndb.Key(Winery, int(winery_id), Wine, int(wine_id))

        post = self.request.POST

        userwine = UserWine(parent=wine_key)

        try:
            post['user'] = User.get_current_user()
            key = userwine.create(post)
            Event.create(self.request.remote_addr, "UserWine", key)
        except ValueError as e:
            self.response.status = "400 Bad Request"
            self.response.write(str(e))
            return

        json_response(self, userwine)
コード例 #15
0
    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)
コード例 #16
0
    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)
コード例 #17
0
    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)
コード例 #18
0
ファイル: debug_handler.py プロジェクト: alumb/WineBits
 def get(self):
     qry = User.query()
     results = qry.fetch(MAX_RESULTS)
     
     json_response(self, [user for user in results])