def delete_product(product_id):
	product = Product.query(Product.product_id == product_id).get()
	if product is None:
		return make_error(404,"This product does not exist, so can't be deleted.")
	product.key.delete()
	return {
		'success': "Product deleted successfully."
	}
def create_product(product_id=None,product_name=None):
	if product_id is None or len(product_id) <= 3:
		product_id = random_key(10)

	existing_products = Product.query(Product.product_id == product_id).fetch(1)

	if len(existing_products) != 0:
		import logging
		logging.error('Product with ID "' + product_id + '" already exists.' )
		return make_error(400,'A product with ID ' + product_id + ' already exists, overwriting is forbidden.')

	product = Product(product_id=product_id)
	if product_name is not None:
		product.product_name = product_name
	product.put()
	return product.product_id
def list_products(start_token=''):
	items_per_page = 100
	cursor = Cursor(urlsafe=start_token)
	products, next_cursor, more = Product.query().order(Product.product_id).fetch_page(items_per_page,start_cursor=cursor)

	items = []
	for product in products:
		items.append({
			'product_id': product.product_id,
			'product_name': product.product_name
		})

	response = {
		'kind': api_id + '#productList',
		'totalItems': len(products),
		'itemsPerPage': items_per_page,
		'items': items
	}

	if more and next_cursor:
		response['nextPageToken'] = next_cursor
	return response