]> git.openstreetmap.org Git - osqa.git/blob - forum/middleware/pagesize.py
deleting the test file
[osqa.git] / forum / middleware / pagesize.py
1 # used in questions
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
12
13         try:
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
18
19         except ValueError:
20             pagesize  = user_page_size
21         
22         # save this pagesize to user database
23         if pagesize_changed:
24             if request.user.is_authenticated():
25                 user = request.user
26                 user.questions_per_page = pagesize
27                 user.save()
28         # put pagesize into session
29         request.session["pagesize"] = pagesize
30
31     def process_exception(self,request,exception):
32         import logging
33         logging.debug('have exception %s' % str(exception))