forked from hacktoolkit/django-htk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
views.py
86 lines (76 loc) · 2.31 KB
/
views.py
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import re
from django.core.urlresolvers import reverse
from django.http import Http404
from django.http import HttpResponse
from django.shortcuts import get_object_or_404
from django.shortcuts import redirect
from django.template import RequestContext
from django.template import TemplateDoesNotExist
from django.template import loader
def health_check(request):
response = HttpResponse(status=200)
return response
def generic_template_view(request, template_name, context_dict=None, content_type='text/html'):
try:
template = loader.get_template(template_name)
context_dict = context_dict or {}
context = RequestContext(request, context_dict)
response = HttpResponse(template.render(context), content_type=content_type)
except TemplateDoesNotExist:
response = None
raise Http404
return response
def google_site_verification(request, code):
template_name = 'site_verification/google%s.html' % code
response = generic_template_view(request, template_name)
return response
def html_site_verification(request, code):
template_name = 'site_verification/%s--.html' % code
response = generic_template_view(
request,
template_name
)
return response
def bing_site_auth(request):
template_name = 'site_verification/BingSiteAuth.xml'
response = generic_template_view(
request,
template_name,
content_type='text/xml'
)
return response
def robots(request):
template_name = 'robots.txt'
context_dict = {
'request' : {
'request' : request,
'host' : request.get_host(),
},
}
response = generic_template_view(
request,
template_name,
context_dict=context_dict,
content_type='text/plain'
)
return response
def redir(request):
url = request.GET.get('url', None)
if url:
if not re.match('^https?://', url):
url = 'http://%s' % url
else:
pass
response = redirect(url)
else:
response = redirect('/')
return response
##################################################
# error pages
def error_view(request):
path_no_slash = request.path[1:]
response = generic_template_view(
request,
'%s.html' % path_no_slash
)
return response