django-orchestra/orchestra/contrib/resources/api.py

20 lines
593 B
Python
Raw Normal View History

2015-07-27 12:55:35 +00:00
import json
from urllib.parse import parse_qs
from django.http import HttpResponse
from .helpers import get_history_data
from .models import ResourceData
def history_data(request):
ids = map(int, parse_qs(request.META['QUERY_STRING'])['ids'][0].split(','))
queryset = ResourceData.objects.filter(id__in=ids)
history = get_history_data(queryset)
def default(obj):
if isinstance(obj, set):
return list(obj)
return obj
response = json.dumps(history, default=default, indent=4)
return HttpResponse(response, content_type="application/json")