Ejemplo n.º 1
0
 def PUT(self, id, **kwargs):
     try:
         product = products.find_one({'_id': ObjectId(id)})
         
         if product:
             data = validate_data(**kwargs)
             products.update({'_id': product['_id']}, {'$set': data})
             product = products.find_one({'id': ObjectId(id)})
             return 'Product with ID {0} has been updated:\n{1}'.format(id, json.dumps(product, indent=4, separators=(',', ': ')))
         else:
             return 'No product with the ID {0} found'.format(id)
     except Exception, e:
         print e
Ejemplo n.º 2
0
    def POST(self, **kwargs):
        data = validate_data(**kwargs)
        _id = products.insert(data)

        return 'A new product with ID {0} has been created'.format(_id)