1 from forum.settings import MAINTAINANCE_MODE, APP_LOGO, APP_TITLE
\r
3 from forum.http_responses import HttpResponseServiceUnavailable
\r
5 class RequestUtils(object):
\r
9 def set_sort_method(self, sort):
\r
10 self.request.session['questions_sort_method'] = sort
\r
12 def sort_method(self, default):
\r
13 sort = self.request.REQUEST.get('sort', None)
\r
15 return self.request.session.get('questions_sort_method', default)
\r
17 self.set_sort_method(sort)
\r
20 def page_size(self, default):
\r
21 pagesize = self.request.REQUEST.get('pagesize', None)
\r
22 if pagesize is None:
\r
23 return int(self.request.session.get('questions_pagesize', default))
\r
25 self.request.session['questions_pagesize'] = pagesize
\r
26 return int(pagesize)
\r
28 def process_request(self, request):
\r
29 if MAINTAINANCE_MODE.value is not None and isinstance(MAINTAINANCE_MODE.value.get('allow_ips', None), list):
\r
30 ip = request.META['REMOTE_ADDR']
\r
32 if not ip in MAINTAINANCE_MODE.value['allow_ips']:
\r
33 return HttpResponseServiceUnavailable(MAINTAINANCE_MODE.value.get('message', ''))
\r
35 if request.session.get('redirect_POST_data', None):
\r
36 request.POST = request.session.pop('redirect_POST_data')
\r
37 request.META['REQUEST_METHOD'] = "POST"
\r
39 self.request = request
\r
40 request.utils = self
\r