defpaginate(request,objects,count=10,param_name='page'):""" Shortcut for paginating by some object """paginator=Paginator(objects,count)try:pagenum=int(request.GET.get('%s'%param_name,'1'))exceptValueError:pagenum=1try:result=paginator.page(pagenum)except(EmptyPage,InvalidPage):result=paginator.page(paginator.num_pages)returnresult