From 6efcf5ac180efa7617c3f4093ddaa609d7c2ea05 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 27 Nov 2024 18:11:22 +0100 Subject: [PATCH] add result for dpp and for chid --- device/models.py | 1 + did/views.py | 31 +++++++++++++++++++------------ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/device/models.py b/device/models.py index 7c1827f..cd77389 100644 --- a/device/models.py +++ b/device/models.py @@ -116,6 +116,7 @@ class Device: return annotation = annotations.first() self.last_evidence = Evidence(annotation.uuid) + self.uuid = annotation.uuid def is_eraseserver(self): if not self.uuids: diff --git a/did/views.py b/did/views.py index 8517b6c..3d4ef35 100644 --- a/did/views.py +++ b/did/views.py @@ -6,6 +6,7 @@ from django.views.generic.base import TemplateView from device.models import Device from dpp.api_dlt import ALGORITHM from dpp.models import Proof +from dpp.api_dlt import PROOF_TYPE logger = logging.getLogger('django') @@ -98,18 +99,24 @@ class PublicDeviceWebView(TemplateView): 'data': data, } - # if self.dpp: - # data['document'] = self.dpp.snapshot.json_hw - # last_dpp = self.get_last_dpp() - # url_last = '' - # if last_dpp: - # url_last = 'https://{host}/{did}'.format( - # did=last_dpp.key, host=app.config.get('HOST') - # ) - # data['url_last'] = url_last - # for c in self.dpp.snapshot.components: - # components.append({c.type: c.chid}) - # return result + if len(self.pk.split(":")) > 1: + data['document'] = json.dumps(self.object.last_evidence.doc) + + self.object.get_evidences() + last_dpp = Proof.objects.filter( + uuid__in=self.object.uuids, type=PROOF_TYPE['IssueDPP'] + ).order_by("-timestamp").first() + + key = self.pk + if last_dpp: + key = last_dpp.signature + + url = "https://{}/did/{}".format( + self.request.get_host(), + key + ) + data['url_last'] = url + return result dpps = [] self.object.initial()