From 47cf19f1296c21a4069ad606edf4fed8f76e44e4 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 16 Jan 2024 14:00:05 +0100 Subject: [PATCH] add new field type in model DID --- idhub/admin/views.py | 4 ++-- idhub/models.py | 13 ++++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/idhub/admin/views.py b/idhub/admin/views.py index 690c319..5d8d15c 100644 --- a/idhub/admin/views.py +++ b/idhub/admin/views.py @@ -639,13 +639,13 @@ class DidRegisterView(Credentials, CreateView): icon = 'bi bi-patch-check-fill' wallet = True model = DID - fields = ('label',) + fields = ('label', 'type') success_url = reverse_lazy('idhub:admin_dids') object = None def form_valid(self, form): form.instance.user = self.request.user - form.instance.set_did(form.instance.type) + form.instance.set_did() form.save() messages.success(self.request, _('DID created successfully')) Event.set_EV_ORG_DID_CREATED_BY_ADMIN(form.instance) diff --git a/idhub/models.py b/idhub/models.py index eb17650..141a335 100644 --- a/idhub/models.py +++ b/idhub/models.py @@ -403,6 +403,13 @@ class Event(models.Model): class DID(models.Model): + class Types(models.IntegerChoices): + KEY = 1, "Key" + WEB = 2, "Web" + type = models.PositiveSmallIntegerField( + _("Type"), + choices=Types.choices, + ) created_at = models.DateTimeField(auto_now=True) label = models.CharField(_("Label"), max_length=50) did = models.CharField(max_length=250) @@ -424,11 +431,11 @@ class DID(models.Model): return True return False - def set_did(self, type): + def set_did(self): self.key_material = generate_did_controller_key() - if type == "key": + if self.type == self.Types.KEY: self.did = keydid_from_controller_key(self.key_material) - elif type == "web": + elif self.type == self.Types.WEB: didurl, document = webdid_from_controller_key(self.key_material) self.did = didurl self.didweb_document = document