Ejemplo n.º 1
0
    def post(self):
        """

        >>> v = WineryBaseHandler()
        >>> v.request.POST = {'name':'Winery'}
        >>> v.post()
        >>> v.response.content_type
        'application/json'
        >>> v.response.last_write
        '{..."key": "stub-key"...}'

        """
        post = self.request.POST

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

        json_response(self, winery)
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
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)
Ejemplo n.º 4
0
    def post(self):
        """

        >>> v = WineryBaseHandler()
        >>> v.request.POST = {'name':'Winery'}
        >>> v.post()
        >>> v.response.content_type
        'application/json'
        >>> v.response.last_write
        '{..."key": "stub-key"...}'

        """
        post = self.request.POST

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

        json_response(self, winery)
Ejemplo n.º 5
0
    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)
Ejemplo n.º 6
0
 def delete(self, winery_id, wine_id, userwine_id, tasting_id):
     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.delete()
     Event.delete(self.request.remote_addr, "WineTasting", tasting_key)
     json_response(self, {"success": True})
Ejemplo n.º 7
0
    def post(self, winery_id):
        """
        POST /winery/12345/wine => create a wine for winery
        """
        winery_key = ndb.Key(Winery, int(winery_id))
        winery = winery_key.get()

        if not winery:
            self.response.status = "404 Not Found"
            self.response.write("404 Not found.")
            return

        post = self.request.POST

        wine = Wine(parent=winery_key)
        try:
            key = wine.create(post, winery)
            wine.update(winery)
            Event.create(self.request.remote_addr, "Wine", key)
        except ValueError as e:
            self.response.status = "400 Bad Request"
            self.response.write(str(e))
            return

        json_response(self, wine)
Ejemplo n.º 8
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})
Ejemplo n.º 9
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)
Ejemplo n.º 10
0
 def delete(self, winery_id, wine_id, userwine_id, tasting_id):
     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.delete()
     Event.delete(self.request.remote_addr, "WineTasting", tasting_key)
     json_response(self, {"success": True})
Ejemplo n.º 11
0
    def get(self, winery_id, wine_id):
        wine_key = ndb.Key(Winery, int(winery_id), Wine, int(wine_id))
        wine = wine_key.get()

        if not wine:
            self.response.status = "404 Not Found"
            self.response.write("404 Not found.")
            return

        json_response(self, wine)
Ejemplo n.º 12
0
    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)
Ejemplo n.º 13
0
    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)
Ejemplo n.º 14
0
    def get(self, winery_id, wine_id, userwine_id, tasting_id):

        tasting_key = ndb.Key(Winery, int(winery_id), Wine, int(wine_id),
                              UserWine, int(userwine_id), WineTasting, int(tasting_id))
        tasting = tasting_key.get()
        if not tasting:
            self.response.write("404 Not Found")
            self.response.status = "404 Not Found"
            return

        json_response(self, tasting)
Ejemplo n.º 15
0
    def get(self, winery_id, wine_id, userwine_id, tasting_id):

        tasting_key = ndb.Key(Winery, int(winery_id), Wine, int(wine_id),
                              UserWine, int(userwine_id), WineTasting,
                              int(tasting_id))
        tasting = tasting_key.get()
        if not tasting:
            self.response.write("404 Not Found")
            self.response.status = "404 Not Found"
            return

        json_response(self, tasting)
Ejemplo n.º 16
0
    def get(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

        qry = WineTasting.query(ancestor=userwine.key)
        results = qry.fetch(MAX_RESULTS)

        json_response(self, results)
Ejemplo n.º 17
0
    def get(self, winery_id):
        """
        /winery/12345/wine => all wines for winery
        """
        winery_key = ndb.Key(Winery, int(winery_id))
        winery = winery_key.get()

        if not winery:
            self.response.write("404 Not Found")
            self.response.status = "404 Not Found"
            return

        json_response(self, Wine.winery_query(winery))
Ejemplo n.º 18
0
    def get(self, winery_id, wine_id):

        wine_key = ndb.Key(Winery, int(winery_id), Wine, int(wine_id))
        wine = wine_key.get()

        if not wine:
            self.response.write("404 Not Found")
            self.response.status = "404 Not Found"
            return

        qry = UserWine.query(ancestor=wine_key)
        results = qry.fetch(MAX_RESULTS)

        json_response(self, [x for x in results])
Ejemplo n.º 19
0
    def get(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

        qry = WineTasting.query(ancestor=userwine.key)
        results = qry.fetch(MAX_RESULTS)

        json_response(self, results)
Ejemplo n.º 20
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)
Ejemplo n.º 21
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)
Ejemplo n.º 22
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})
Ejemplo n.º 23
0
    def post(self, winery_id, wine_id, userwine_id):
        userwine_key = ndb.Key(Winery, int(winery_id), Wine, int(wine_id), UserWine, int(userwine_id))

        post = self.request.POST

        tasting = WineTasting(parent=userwine_key)

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

        json_response(self, tasting)
Ejemplo n.º 24
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)
Ejemplo n.º 25
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)
Ejemplo n.º 26
0
    def get(self):
        if not 'q' in self.request.GET:
            query = ""
        else:
            query = self.request.GET['q']

        wine_index = search.Index(name="wines")
        winery_index = search.Index(name="wineries")
        
        wine_limiter = search.QueryOptions(
            returned_fields=['year', 'name', 'varietal', 'winery', 'varietal',
                             'winetype',
                             'upc', 'verified', 'id', 'winery_id', 'rank'])
        winery_limiter = search.QueryOptions(
            returned_fields=['name', 'location', 'verified', 'id', 'rank'])

        # this can throw a search.Error, which should be a 500, I think?
        wine_query = search.Query(query_string=query, options=wine_limiter)
        winery_query = search.Query(query_string=query, options=winery_limiter)

        wine_results = wine_index.search(wine_query)
        winery_results = winery_index.search(winery_query)
       
        def to_dict(doc):
            dict_ = {}
            for field in doc.fields:
                try:
                    dict_[field.name] = int(field.value)
                except:
                    dict_[field.name] = str(field.value)
            return dict_
        
        def with_url(dict_):
            if 'id' in dict_ and not 'winery_id' in dict_:
                dict_['url'] = "/winery/" + str(dict_['id'])
            elif 'id' in dict_ and 'winery_id' in dict_:
                dict_['url'] = ("/winery/" + str(dict_['winery_id']) +
                                "/wine/" + str(dict_['id']))
            return dict_

        wines = [with_url(to_dict(wine)) for wine in wine_results.results]
        wineries = [with_url(to_dict(winery)) for winery in winery_results.results]

        response = {'wines': wines, 'wineries': wineries}
        
        json_response(self, response)
Ejemplo n.º 27
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)
Ejemplo n.º 28
0
    def post(self, winery_id, wine_id, userwine_id):
        userwine_key = ndb.Key(Winery, int(winery_id), Wine, int(wine_id),
                               UserWine, int(userwine_id))

        post = self.request.POST

        tasting = WineTasting(parent=userwine_key)

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

        json_response(self, tasting)
Ejemplo n.º 29
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
            })
Ejemplo n.º 30
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)
Ejemplo n.º 31
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)
Ejemplo n.º 32
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)
Ejemplo n.º 33
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)
Ejemplo n.º 34
0
    def get(self, winery_id):
        """
        >>> v = Winery()
        >>> key = v.create({'name':'winery'})
        >>> ndb.Key.load_get(v )

        >>> h = WineryHandler()
        >>> h.get('12345')
        >>> h.response.content_type
        'application/json'
        >>> h.response.last_write
        '{..."name": "winery",..."key":...}'
        """

        winery_key = ndb.Key(Winery, int(winery_id))
        winery = winery_key.get()
        if not winery:
            self.response.write("404 Not Found")
            self.response.status = "404 Not Found"
            return

        json_response(self, winery)
Ejemplo n.º 35
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)
Ejemplo n.º 36
0
    def get(self, winery_id):
        """
        >>> v = Winery()
        >>> key = v.create({'name':'winery'})
        >>> ndb.Key.load_get(v )

        >>> h = WineryHandler()
        >>> h.get('12345')
        >>> h.response.content_type
        'application/json'
        >>> h.response.last_write
        '{..."name": "winery",..."key":...}'
        """

        winery_key = ndb.Key(Winery, int(winery_id))
        winery = winery_key.get()
        if not winery:
            self.response.write("404 Not Found")
            self.response.status = "404 Not Found"
            return

        json_response(self, winery)
Ejemplo n.º 37
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})
Ejemplo n.º 38
0
    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)
Ejemplo n.º 39
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})
Ejemplo n.º 40
0
 def get(self):
     qry = User.query()
     results = qry.fetch(MAX_RESULTS)
     
     json_response(self, [user for user in results])
Ejemplo n.º 41
0
 def get(self, country, region):
     json_response(self, regions.subregions_for_country(country, region))
Ejemplo n.º 42
0
 def get(self):
     response = [varietal
                 for varietal in wine_types.wine_options]
     json_response(self, response)
Ejemplo n.º 43
0
 def get(self):
     if 'fuzzy' in self.request.GET:
         json_response(self, Winery.all_fuzzy_locations())
     else:
         json_response(self, regions.location_list)
Ejemplo n.º 44
0
    def get(self):
        """
        /winery?
        /winery?country=Canada
        /winery?region=British Columbia
        /winery?subregion=Okanagan Valley
        /winery?name="Black Hills Estate"
        /winery?location="Canada - British Columbia: Okanagan Valley"
        /winery?location_fuzzy="Somewhere"
        """
        get = self.request.GET
        if 'subregion' in get:
            json_response(self, Winery.subregion_query(get['subregion']))
            return
        if 'region' in get:
            json_response(self, Winery.region_query(get['region']))
            return
        if 'country' in get:
            json_response(self, Winery.country_query(get['country']))
            return
        if 'name' in get:
            json_response(self, Winery.name_query(get['name']))
            return
        if 'location' in get:
            json_response(self, Winery.location_query(get['location']))
            return
        if 'location_fuzzy' in get:
            json_response(self, Winery.location_fuzzy_query(
                          get['location_fuzzy']))
            return
        if 'verified_by' in get:
            json_response(self, Winery.verified_by_query(
                          get['verified_by']))
            return
        if 'verified' in get:
            verified = False
            if get['verified'].lower() == 'true':
                verified = True
            json_response(self, Winery.verified_query(verified))
            return
        if 'q' in get and get['q'] != '':
            json_response(self, Winery.search(get['q']))
            return

        #if no params, return entire list.
        json_response(self, Winery.all_query())
Ejemplo n.º 45
0
 def get(self):
     json_response(self, regions.countries)
Ejemplo n.º 46
0
 def get(self):
     json_response(self, wine_types.types)
Ejemplo n.º 47
0
 def get(self, country):
     json_response(self, regions.regions_for_country(country))
Ejemplo n.º 48
0
 def get(self):
     response = [varietal for varietal in wine_types.wine_options]
     json_response(self, response)
Ejemplo n.º 49
0
    def get(self):
        """
        /winery?
        /winery?country=Canada
        /winery?region=British Columbia
        /winery?subregion=Okanagan Valley
        /winery?name="Black Hills Estate"
        /winery?location="Canada - British Columbia: Okanagan Valley"
        /winery?location_fuzzy="Somewhere"
        """
        get = self.request.GET
        if 'subregion' in get:
            json_response(self, Winery.subregion_query(get['subregion']))
            return
        if 'region' in get:
            json_response(self, Winery.region_query(get['region']))
            return
        if 'country' in get:
            json_response(self, Winery.country_query(get['country']))
            return
        if 'name' in get:
            json_response(self, Winery.name_query(get['name']))
            return
        if 'location' in get:
            json_response(self, Winery.location_query(get['location']))
            return
        if 'location_fuzzy' in get:
            json_response(self,
                          Winery.location_fuzzy_query(get['location_fuzzy']))
            return
        if 'verified_by' in get:
            json_response(self, Winery.verified_by_query(get['verified_by']))
            return
        if 'verified' in get:
            verified = False
            if get['verified'].lower() == 'true':
                verified = True
            json_response(self, Winery.verified_query(verified))
            return
        if 'q' in get and get['q'] != '':
            json_response(self, Winery.search(get['q']))
            return

        #if no params, return entire list.
        json_response(self, Winery.all_query())