diff --git a/ingest/admin.py b/ingest/admin.py index 02eb883..3ecc069 100644 --- a/ingest/admin.py +++ b/ingest/admin.py @@ -1,8 +1,20 @@ +from django.utils.html import escape, mark_safe from django.contrib import admin +import json + from .models import DecompressedEvent @admin.register(DecompressedEvent) class DecompressedEventAdmin(admin.ModelAdmin): list_display = ["timestamp", "project"] + exclude = ["data"] + + readonly_fields = [ + 'pretty_data', + ] + + def pretty_data(self, obj): + return mark_safe("
" + escape(json.dumps(json.loads(obj.data), indent=2)) + "") + pretty_data.short_description = "Data" diff --git a/ingest/views.py b/ingest/views.py index 7ec0c30..2fb45fa 100644 --- a/ingest/views.py +++ b/ingest/views.py @@ -1,3 +1,5 @@ +import json # TODO consider faster APIs + from rest_framework import permissions, status from rest_framework.response import Response from rest_framework.views import APIView @@ -19,7 +21,10 @@ class BaseIngestAPIView(APIView): http_method_names = ["post"] def process_event(self, event_data, request, project): - DecompressedEvent.objects.create(project=project, data=event_data) + DecompressedEvent.objects.create( + project=project, + data=json.dumps(event_data), # TODO don't parse-then-print for BaseIngestion + ) class IngestEventAPIView(BaseIngestAPIView):