DPP/DLT functionality #36
44
dpp/views.py
44
dpp/views.py
|
@ -1,11 +1,13 @@
|
||||||
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from django.views.generic.edit import View
|
from django.views.generic.edit import View
|
||||||
from django.http import JsonResponse
|
from django.http import JsonResponse
|
||||||
|
|
||||||
from evidence.xapian import search
|
|
||||||
from dpp.models import Proof
|
|
||||||
from dpp.api_dlt import ALGORITHM
|
from dpp.api_dlt import ALGORITHM
|
||||||
|
from evidence.models import Evidence
|
||||||
|
from evidence.parse import Build
|
||||||
|
from dpp.models import Proof
|
||||||
|
|
||||||
logger = logging.getLogger('django')
|
logger = logging.getLogger('django')
|
||||||
|
|
||||||
|
@ -20,27 +22,23 @@ class ProofView(View):
|
||||||
proof = Proof.objects.filter(timestamp=timestamp).first()
|
proof = Proof.objects.filter(timestamp=timestamp).first()
|
||||||
if not proof:
|
if not proof:
|
||||||
return JsonResponse({}, status=404)
|
return JsonResponse({}, status=404)
|
||||||
|
|
||||||
ev_uuid = 'uuid:"{}"'.format(proof.uuid)
|
ev = Evidence(proof.uuid)
|
||||||
matches = search(None, ev_uuid, limit=1)
|
if not ev.doc:
|
||||||
if not matches or matches.size() < 1:
|
|
||||||
return JsonResponse({}, status=404)
|
return JsonResponse({}, status=404)
|
||||||
|
|
||||||
for x in matches:
|
dev = Build(ev.doc, None, check=True)
|
||||||
snap = x.document.get_data()
|
doc = dev.get_phid()
|
||||||
|
|
||||||
data = {
|
|
||||||
"algorithm": ALGORITHM,
|
|
||||||
"document": snap
|
|
||||||
}
|
|
||||||
|
|
||||||
d = {
|
data = {
|
||||||
'@context': ['https://ereuse.org/proof0.json'],
|
"algorithm": ALGORITHM,
|
||||||
'data': data,
|
"document": json.dumps(doc)
|
||||||
}
|
}
|
||||||
response = JsonResponse(d, status=200)
|
|
||||||
response["Access-Control-Allow-Origin"] = "*"
|
|
||||||
return response
|
|
||||||
|
|
||||||
return JsonResponse({}, status=404)
|
|
||||||
|
|
||||||
|
d = {
|
||||||
|
'@context': ['https://ereuse.org/proof0.json'],
|
||||||
|
'data': data,
|
||||||
|
}
|
||||||
|
response = JsonResponse(d, status=200)
|
||||||
|
response["Access-Control-Allow-Origin"] = "*"
|
||||||
|
return response
|
||||||
|
|
Loading…
Reference in a new issue