def get_page_in_request_data(request_data):
	try:
		page = request_data["page"]
	except Exception, e:
		page = 1

	return page

def get_pagination_values(list_length, page, num_per_page):
	"""
		-> (number, number, number, number)
		Return:
		- number total of pages
		- current page
		- start of range
		- end of range
	"""
	# There are objects
	if list_length > 0:
		total_pages    = ((list_length - 1) / num_per_page) + 1

		# Validation
		if page > total_pages:
			page = total_pages

		if page < 1:
			page = 1

		start = (page - 1) * num_per_page
		end   = start + num_per_page
	else:
		total_pages = 1
		page        = 1
		start = 0
		end   = 0

	return (total_pages, page, start, end)

def response_success_object(dic, a_object=None):
	#if a_object:
	dic["object"]  = a_object
	dic["success"] = True

def response_success_object_pagination(dic, object_list, request_data, num_per_page=10):

	page = get_page_in_request_data(request_data)
	total_pages, page, start, end = get_pagination_values(len(object_list), page, num_per_page)

	dic["pagination"] = {
		"current" : page,
		"pages"   : total_pages
	}

	# Normal response success
	response_success_object(dic, object_list[start:end])