diff options
author | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2009-07-26 22:33:56 -0400 |
---|---|---|
committer | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2009-07-26 22:33:56 -0400 |
commit | faf167aed99ac4e28927f729b7c7bc94a47ef139 (patch) | |
tree | db94fc2e3af7c23fdced6b48768283b9ca8f1019 /middleware | |
parent | a7a5d993c680a2fa2a541951d99742090a716807 (diff) | |
download | askbot-faf167aed99ac4e28927f729b7c7bc94a47ef139.tar.gz askbot-faf167aed99ac4e28927f729b7c7bc94a47ef139.tar.bz2 askbot-faf167aed99ac4e28927f729b7c7bc94a47ef139.zip |
merged in latest Mikes changes
Diffstat (limited to 'middleware')
-rw-r--r-- | middleware/pagesize.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/middleware/pagesize.py b/middleware/pagesize.py new file mode 100644 index 00000000..bb6c7aa3 --- /dev/null +++ b/middleware/pagesize.py @@ -0,0 +1,29 @@ +# used in questions +QUESTIONS_PAGE_SIZE = 10 +class QuestionsPageSizeMiddleware(object): + def process_request(self, request): + # Set flag to False by default. If it is equal to True, then need to be saved. + pagesize_changed = False + # get pagesize from session, if failed then get default value + user_page_size = request.session.get("pagesize", QUESTIONS_PAGE_SIZE) + # set pagesize equal to logon user specified value in database + if request.user.is_authenticated() and request.user.questions_per_page > 0: + user_page_size = request.user.questions_per_page + + try: + # get new pagesize from UI selection + pagesize = int(request.GET.get('pagesize', user_page_size)) + if pagesize <> user_page_size: + pagesize_changed = True + + except ValueError: + pagesize = user_page_size + + # save this pagesize to user database + if pagesize_changed: + if request.user.is_authenticated(): + user = request.user + user.questions_per_page = pagesize + user.save() + # put pagesize into session + request.session["pagesize"] = pagesize
\ No newline at end of file |