@auth.requires_login()
def register_order():
	
	"""
	This function will register the user's shopping cart
	in a database record. This record is a order that
	contains payment info and will serve as a history
	of the user transactions.

	After the order is recorded, the session of the 
	shopping cart will be clean.
	"""

	## if the user were not logged in when it selected classes to enroll
	## then it can select classses it is already enrolled
	## and the classes will be in the shopping cart.
	## to avoid that:
	for class_id in session.cart:
		cart_class = Class(id=int(class_id))
		if not can_enroll(cart_class):
			session.flash = T('You are already enrolled in this class to %s, so we removed it from your shopping cart.') % cart_class.course.title
			session.cart.remove(class_id)
			redirect(URL('shopping_cart'))

	order = Order.insert(
						user_id = auth.user.id,
						order_date = request.now,
						products = [Class(id=cart_class) for cart_class in session.cart],
						status = 1
						)
	session.order = order
	session.cart = []

	message = T("We just received your order number %s:") % order.token
	for product in order.products:
		message += '\n'
		message += T("- %s from %s to %s") % (product.course.title, product.start_date, product.end_date)
	message += '\n'
	message += order.amount % T("Amount: R$%.2f")
	message += '\n\n'
	message += T("We will wait and let you know when your payment is confirmed.")
	message += '\n'
	message += T("Thank you for your purchase!")

	mail.send(to=order.user_id.email,
			subject=T("We received your order!"),
			message=message
			)
	redirect(URL('pay_courses'))
dataset/ETHPy150Open juliarizza/web2courses/controllers/payments.py/register_order/swapped operands of `%`