doc fix
[fnpdjango.git] / fnpdjango / utils / views.py
1 """
2 View-specific utilities.
3 """
4
5 from .. import app_settings
6 from django.http import HttpResponse, HttpResponseRedirect
7
8
9 def serve_file(url):
10     """Serves an URL either though Nginx's X-accel, or by redirection.""" 
11     if app_settings.XACCEL:
12         response = HttpResponse()
13         response['Content-Type'] = ""
14         response['X-Accel-Redirect'] = url
15         return response
16     else:
17         return HttpResponseRedirect(url)
18
19
20 def set_current_object(request, obj, in_url=True):
21     request.CURRENT_OBJECT = obj
22     request.CURRENT_OBJECT_IN_URL = in_url
23
24
25 def get_current_object(request, for_url=False):
26     if for_url and not getattr(request, 'CURRENT_OBJECT_IN_URL', True):
27         return None
28     return getattr(request, 'CURRENT_OBJECT', None)