Пример #1
0
    def post(self):
        logging.debug("In AddItemHandler")
        self.response.headers['Content-Type'] = 'application/json'

        # Do basic update validation
        user = get_user_for_update(self.request, self.response)
        if user == None:
            return

        # Ensure this item does not already exist for this user
        itemtype = self.request.get('itemtype')
        name = self.request.get('itemname')
        item = GameItem.get(user, itemtype, name)
        if item != None:
            write_response(self.response, "11", None, 
                           "Item with name %s and type %s already exists for user %s" %
                           (name, itemtype, user.name))
            return

        # Add item to user
        item = GameItem()
        item.itemtype = itemtype
        item.name = name
        item.user = user
        item.blob = self.request.get('blob')
        try:
            item.quantity = int(self.request.get('quantity'))
        except ValueError:
            write_response(self.response, "9", None, 
                           "quantity %s must be an integer" % self.request.get('quantity'))
            return None

        item.put()
        write_response(self.response, "0", {})
Пример #2
0
    def post(self):
        """ Just updates the item quantity """
        logging.debug("In UpdateItemHandler")
        self.response.headers['Content-Type'] = 'application/json'

        # Do basic update validation
        user = get_user_for_update(self.request, self.response)
        if user == None:
            return

        # Get User Item
        itemtype = self.request.get('itemtype')
        name = self.request.get('itemname')
        item = GameItem.get(user, itemtype, name)

        if item == None:
            write_response(
                self.response, "12", None,
                "Item type %s with name %s does not exist for user %s." %
                (itemtype, name, self.request.get('name')))
            return

        try:
            item.quantity = int(self.request.get('quantity'))
        except ValueError:
            write_response(
                self.response, "9", None, "quantity %s must be an integer" %
                self.request.get('quantity'))
            return None

        item.blob = self.request.get('blob')
        item.put()
        write_response(self.response, "0", {})
Пример #3
0
    def post(self):
        """ Just updates the item quantity """
        logging.debug("In UpdateItemHandler")
        self.response.headers['Content-Type'] = 'application/json'

        # Do basic update validation
        user = get_user_for_update(self.request, self.response)
        if user == None:
            return

        # Get User Item
        itemtype = self.request.get('itemtype')
        name = self.request.get('itemname')
        item = GameItem.get(user, itemtype, name)

        if item == None:
            write_response(self.response, "12", None, "Item type %s with name %s does not exist for user %s." % (itemtype, name, self.request.get('name')))
            return

        try:
            item.quantity = int(self.request.get('quantity'))
        except ValueError:
            write_response(self.response, "9", None, 
                           "quantity %s must be an integer" % self.request.get('quantity'))
            return None

        item.blob = self.request.get('blob')
        item.put()
        write_response(self.response, "0", {})
Пример #4
0
    def post(self):
        logging.debug("In AddItemHandler")
        self.response.headers['Content-Type'] = 'application/json'

        # Do basic update validation
        user = get_user_for_update(self.request, self.response)
        if user == None:
            return

        # Ensure this item does not already exist for this user
        itemtype = self.request.get('itemtype')
        name = self.request.get('itemname')
        item = GameItem.get(user, itemtype, name)
        if item != None:
            write_response(
                self.response, "11", None,
                "Item with name %s and type %s already exists for user %s" %
                (name, itemtype, user.name))
            return

        # Add item to user
        item = GameItem()
        item.itemtype = itemtype
        item.name = name
        item.user = user
        item.blob = self.request.get('blob')
        try:
            item.quantity = int(self.request.get('quantity'))
        except ValueError:
            write_response(
                self.response, "9", None, "quantity %s must be an integer" %
                self.request.get('quantity'))
            return None

        item.put()
        write_response(self.response, "0", {})
Пример #5
0
    def post(self):
        logging.debug("In AddItemHandler")
        self.response.headers['Content-Type'] = 'application/json'

        # Do basic update validation
        user = get_user_for_update(self.request, self.response)
        if user == None:
            return

        itemlist = []
        items = GameItem.list(user)
        for item in items:
            itemdict = item.to_dict()
            itemlist.append(itemdict)

        write_response(self.response, "0", json.dumps(itemlist))
Пример #6
0
    def post(self):
        logging.debug("In AddItemHandler")
        self.response.headers['Content-Type'] = 'application/json'

        # Do basic update validation
        user = get_user_for_update(self.request, self.response)
        if user == None:
            return

        itemlist = []
        items = GameItem.list(user)
        for item in items:
            itemdict = item.to_dict()
            itemlist.append(itemdict)

        write_response(self.response, "0", json.dumps(itemlist))
Пример #7
0
    def post(self):
        """ Removes an item from a user """
        logging.debug("In GetItemHandler")
        self.response.headers['Content-Type'] = 'application/json'

        # Do basic update validation
        user = get_user_for_update(self.request, self.response)
        if user == None:
            return

        # Get User Item
        itemtype = self.request.get('itemtype')
        name = self.request.get('itemname')
        item = GameItem.get(user, itemtype, name)
        if item == None:
            write_response(self.response, "12", None, "Item type %s with name %s does not exist for user %s." % (itemtype, name, self.request.get('name')))
        else:
            write_response(self.response, "0", json.dumps(item.to_dict()))
        return 
Пример #8
0
    def post(self):
        """ Removes an item from a user """
        logging.debug("In GetItemHandler")
        self.response.headers['Content-Type'] = 'application/json'

        # Do basic update validation
        user = get_user_for_update(self.request, self.response)
        if user == None:
            return

        # Get User Item
        itemtype = self.request.get('itemtype')
        name = self.request.get('itemname')
        item = GameItem.get(user, itemtype, name)
        if item == None:
            write_response(
                self.response, "12", None,
                "Item type %s with name %s does not exist for user %s." %
                (itemtype, name, self.request.get('name')))
        else:
            write_response(self.response, "0", json.dumps(item.to_dict()))
        return