Revision 8b800b6f
b/api/util.py | ||
---|---|---|
79 | 79 |
def wrapper(request, *args, **kwargs): |
80 | 80 |
try: |
81 | 81 |
if request.path.endswith('.json'): |
82 |
type = 'json' |
|
82 |
request.type = 'json'
|
|
83 | 83 |
elif request.path.endswith('.xml'): |
84 |
type = 'xml' |
|
85 |
elif request.META.get('HTTP_ACCEPT', None) == 'application/xml': |
|
86 |
type = 'xml' |
|
84 |
request.type = 'xml' |
|
87 | 85 |
else: |
88 |
type = 'json' |
|
89 |
request.type = type |
|
86 |
request.type = 'json' # Default response format |
|
87 |
for accept in request.META.get('HTTP_ACCEPT', '').split(','): |
|
88 |
if accept == 'application/json': |
|
89 |
break |
|
90 |
elif accept == 'application/xml': |
|
91 |
request.type = 'xml' |
|
92 |
break |
|
90 | 93 |
|
91 | 94 |
if request.method != http_method: |
92 | 95 |
raise BadRequest() |
93 | 96 |
|
94 | 97 |
resp = func(request, *args, **kwargs) |
95 |
resp['Content-Type'] = 'application/xml' if type == 'xml' else 'application/json' |
|
98 |
resp['Content-Type'] = 'application/xml' if request.type == 'xml' else 'application/json'
|
|
96 | 99 |
return resp |
97 | 100 |
except Fault, fault: |
98 | 101 |
return render_fault(request, fault) |
Also available in: Unified diff