filter_dict and new template membership

This commit is contained in:
Cayo Puigdefabregas 2024-01-12 20:09:19 +01:00
parent f54a6f9729
commit 16ea7631dc
2 changed files with 71 additions and 65 deletions

View File

@ -1,6 +1,8 @@
import json import json
import ujson
import pytz import pytz
import datetime import datetime
from collections import OrderedDict
from django.db import models from django.db import models
from django.conf import settings from django.conf import settings
from django.template.loader import get_template from django.template.loader import get_template
@ -525,10 +527,13 @@ class VerificableCredential(models.Model):
self.status = self.Status.ISSUED self.status = self.Status.ISSUED
self.subject_did = did self.subject_did = did
self.issued_on = datetime.datetime.now().astimezone(pytz.utc) self.issued_on = datetime.datetime.now().astimezone(pytz.utc)
self.data = sign_credential( data = sign_credential(
self.render(), self.render(),
self.issuer_did.key_material self.issuer_did.key_material
) )
d_ordered = ujson.loads(data)
d_minimum = self.filter_dict(d_ordered)
self.data = ujson.dumps(d_minimum)
def get_context(self): def get_context(self):
d = json.loads(self.csv_data) d = json.loads(self.csv_data)
@ -544,6 +549,7 @@ class VerificableCredential(models.Model):
'issuance_date': issuance_date, 'issuance_date': issuance_date,
'first_name': self.user.first_name, 'first_name': self.user.first_name,
'last_name': self.user.last_name, 'last_name': self.user.last_name,
'email': self.user.email
} }
context.update(d) context.update(d)
return context return context
@ -564,7 +570,7 @@ class VerificableCredential(models.Model):
return '' return ''
def filter_dict(self, dic): def filter_dict(self, dic):
new_dict = {} new_dict = OrderedDict()
for key, value in dic.items(): for key, value in dic.items():
if isinstance(value, dict): if isinstance(value, dict):
new_value = self.filter_dict(value) new_value = self.filter_dict(value)

View File

@ -9,15 +9,15 @@
"VerifiableAttestation", "VerifiableAttestation",
"MembershipCard" "MembershipCard"
], ],
"id": "https://idhub.pangea.org/credentials/987654321", "id": "[[PLACEHOLDER]]",
"issuer": { "issuer": {
"id": "did:example:5678", "id": "[[PLACEHOLDER]]",
"name": "Pangea Internet Solidari" "name": "[[PLACEHOLDER]]"
}, },
"issuanceDate": "2023-12-06T19:23:24Z", "issuanceDate": "[[PLACEHOLDER]]",
"issued": "2023-12-06T19:23:24Z", "issued": "[[PLACEHOLDER]]",
"validFrom": "2023-12-06T19:23:24Z", "validFrom": "[[PLACEHOLDER]]",
"validUntil": "2024-12-06T19:23:24Z", "validUntil": "[[PLACEHOLDER]]",
"name": [ "name": [
{ {
"value": "Membership Card", "value": "Membership Card",
@ -47,18 +47,18 @@
} }
], ],
"credentialSubject": { "credentialSubject": {
"id": "did:example:1234", "id": "[[PLACEHOLDER]]",
"firstName": "Joan", "firstName": "[[PLACEHOLDER]]",
"lastName": "Pera", "lastName": "[[PLACEHOLDER]]",
"email": "joan.pera@pangea.org", "email": "[[PLACEHOLDER]]",
"typeOfPerson": "natural", "typeOfPerson": "[[PLACEHOLDER]]",
"identityDocType": "DNI", "identityDocType": "[[PLACEHOLDER]]",
"identityNumber": "12345678A", "identityNumber": "[[PLACEHOLDER]]",
"organisation": "Pangea", "organisation": "[[PLACEHOLDER]]",
"membershipType": "individual", "membershipType": "[[PLACEHOLDER]]",
"membershipId": "123456", "membershipId": "[[PLACEHOLDER]]",
"affiliatedSince": "2023-01-01T00:00:00Z", "affiliatedSince": "[[PLACEHOLDER]]",
"affiliatedUntil": "2024-01-01T00:00:00Z" "affiliatedUntil": "[[PLACEHOLDER]]"
}, },
"credentialSchema": { "credentialSchema": {
"id": "https://idhub.pangea.org/vc_schemas/membership-card.json", "id": "https://idhub.pangea.org/vc_schemas/membership-card.json",