forked from phalt/swapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschemas.py
44 lines (26 loc) · 851 Bytes
/
schemas.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
from __future__ import unicode_literals
from django.http import HttpResponse
import json
class JSONResponse():
def __init__(self, resource):
with open('resources/schemas/{0}.json'.format(resource)) as f:
data = json.loads(f.read())
self.data = data
@property
def response(self):
return HttpResponse(
json.dumps(self.data),
content_type="application/json"
)
def people(request):
return JSONResponse('people').response
def planets(request):
return JSONResponse('planets').response
def films(request):
return JSONResponse('films').response
def species(request):
return JSONResponse('species').response
def vehicles(request):
return JSONResponse('vehicles').response
def starships(request):
return JSONResponse('starships').response