2 QUESTIONS_PAGE_SIZE = 10
3 class QuestionsPageSizeMiddleware(object):
4 def process_request(self, request):
5 # Set flag to False by default. If it is equal to True, then need to be saved.
6 pagesize_changed = False
7 # get pagesize from session, if failed then get default value
8 user_page_size = request.session.get("pagesize", QUESTIONS_PAGE_SIZE)
9 # set pagesize equal to logon user specified value in database
10 if request.user.is_authenticated() and request.user.questions_per_page > 0:
11 user_page_size = request.user.questions_per_page
14 # get new pagesize from UI selection
15 pagesize = int(request.GET.get('pagesize', user_page_size))
16 if pagesize <> user_page_size:
17 pagesize_changed = True
20 pagesize = user_page_size
22 # save this pagesize to user database
24 if request.user.is_authenticated():
26 user.questions_per_page = pagesize
28 # put pagesize into session
29 request.session["pagesize"] = pagesize
31 def process_exception(self,request,exception):
33 logging.debug('have exception %s' % str(exception))