devicehub-django/dpp/views.py

45 lines
1.1 KiB
Python
Raw Normal View History

2024-11-28 17:48:50 +00:00
import json
2024-11-28 15:54:31 +00:00
import logging
2024-11-28 17:48:50 +00:00
from django.views.generic.edit import View
from django.http import JsonResponse
2024-11-15 17:56:11 +00:00
from dpp.api_dlt import ALGORITHM
2024-11-28 17:48:50 +00:00
from evidence.models import Evidence
from evidence.parse import Build
from dpp.models import Proof
2024-11-28 15:54:31 +00:00
logger = logging.getLogger('django')
class ProofView(View):
def get(self, request, *args, **kwargs):
timestamp = kwargs.get("proof_id")
2024-11-28 15:54:31 +00:00
for p in Proof.objects.filter():
logger.error(p.timestamp)
proof = Proof.objects.filter(timestamp=timestamp).first()
if not proof:
return JsonResponse({}, status=404)
2024-11-28 17:48:50 +00:00
ev = Evidence(proof.uuid)
if not ev.doc:
return JsonResponse({}, status=404)
2024-11-28 17:48:50 +00:00
dev = Build(ev.doc, None, check=True)
doc = dev.get_phid()
data = {
"algorithm": ALGORITHM,
"document": json.dumps(doc)
}
d = {
'@context': ['https://ereuse.org/proof0.json'],
'data': data,
}
response = JsonResponse(d, status=200)
response["Access-Control-Allow-Origin"] = "*"
return response