-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathviews.py
More file actions
38 lines (31 loc) · 1.27 KB
/
Copy pathviews.py
File metadata and controls
38 lines (31 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from django.http import HttpResponse
from django.conf import settings
from django.utils import simplejson
from django.views.decorators.csrf import csrf_exempt
from ping.defaults import PING_DEFAULT_RESPONSE, PING_DEFAULT_MIMETYPE
from ping.checks import checks
from ping.decorators import http_basic_auth
@csrf_exempt
@http_basic_auth
def status(request):
"""
Returns a simple HttpResponse
"""
response = "<h1>%s</h1>" % getattr(settings, 'PING_DEFAULT_RESPONSE', PING_DEFAULT_RESPONSE)
mimetype = getattr(settings, 'PING_DEFAULT_MIMETYPE', PING_DEFAULT_MIMETYPE)
if request.GET.get('checks') == 'true':
response_dict = checks(request)
response += "<dl>"
for key, value in sorted(response_dict.items()):
response += "<dt>%s</dt>" % str(key)
response += "<dd>%s</dd>" % str(value)
response += "</dl>"
if request.GET.get('fmt') == 'json':
try:
response = simplejson.dumps(response_dict)
except UnboundLocalError:
response_dict = checks(request)
response = simplejson.dumps(response_dict)
response = simplejson.dumps(response_dict, sort_keys=True)
mimetype = 'application/json'
return HttpResponse(response, mimetype=mimetype, status=200)