]> git.openstreetmap.org Git - osqa.git/blob - forum/middleware/request_utils.py
make {% comments %} template tag decoratable and add ability to attach additional...
[osqa.git] / forum / middleware / request_utils.py
1 import forum
2
3 from forum.settings import MAINTAINANCE_MODE, APP_LOGO, APP_TITLE
4
5 from forum.http_responses import HttpResponseServiceUnavailable
6
7
8
9 class RequestUtils(object):
10     def process_request(self, request):
11         if MAINTAINANCE_MODE.value is not None and isinstance(MAINTAINANCE_MODE.value.get('allow_ips', None), list):
12             ip = request.META['REMOTE_ADDR']
13
14             if not ip in MAINTAINANCE_MODE.value['allow_ips']:
15                 return HttpResponseServiceUnavailable(MAINTAINANCE_MODE.value.get('message', ''))
16
17         if request.session.get('redirect_POST_data', None):
18             request.POST = request.session.pop('redirect_POST_data')
19             request.META['REQUEST_METHOD'] = "POST"
20
21         self.request = request
22         forum.REQUEST_HOLDER.request = request
23         return None
24
25     def process_response(self, request, response):
26         forum.REQUEST_HOLDER.request = None
27         return response
28