forked from ietf-tools/datatracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate.py
More file actions
24 lines (20 loc) · 787 Bytes
/
template.py
File metadata and controls
24 lines (20 loc) · 787 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import json
from django.http import HttpResponse
def template(template):
def decorator(fn):
def render(request, *args, **kwargs):
context_data = fn(request, *args, **kwargs)
if isinstance(context_data, HttpResponse):
# View returned an HttpResponse like a redirect
return context_data
else:
# For any other type of data try to populate a template
return render(request, template, context_data)
return render
return decorator
def jsonapi(fn):
def to_json(request, *args, **kwargs):
context_data = fn(request, *args, **kwargs)
return HttpResponse(json.dumps(context_data),
content_type='application/json')
return to_json