Ejemplo n.º 1
0
    def put(self, name):
        data = Item.parser.parse_args()

        item = ItemModel.find_by_name(name)

        if item is None:
            try:
                item = ItemModel(name, **data)
            except:
                {
                    'message':
                    'An error occurred attempting to insert the item into the database'
                }, 500  # Internal Server Error
        else:
            try:
                item.price = data['price']
                item.store_id = data['store_id']
            except:
                {
                    'message':
                    'An error occurred attempting to update the item in the database'
                }, 500  # Internal Server Error

        item.save_to_db()

        return item.json()
Ejemplo n.º 2
0
    def put(self, name):
        data = Item.parser.parse_args()

        item = ItemModel.find_by_name(name)

        if item is None:
            item = ItemModel(name, data['price'], data['store_id'])
        else:
            item.price = data['price']
            item.store_id = data['store_id']
        item.save_to_db()
        return item.json()