From 61e2dc0d9cc8ec6cf2b0f053641ae3d3c3cd34eb Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 29 Feb 2024 13:00:59 +0100 Subject: [PATCH] . --- idhub/admin/views.py | 7 ++++++- idhub/models.py | 5 +++++ idhub/templates/idhub/admin/schemas.html | 2 ++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/idhub/admin/views.py b/idhub/admin/views.py index e2dd58f..d33c3a7 100644 --- a/idhub/admin/views.py +++ b/idhub/admin/views.py @@ -870,7 +870,12 @@ class SchemasDeleteView(SchemasMix): def get(self, request, *args, **kwargs): self.check_valid_user() self.pk = kwargs['pk'] - self.object = get_object_or_404(Schemas, pk=self.pk) + schema.vcredentials.filter(status=VerificableCredential.Status.ISSUED).count() + self.object = get_object_or_404( + Schemas, + pk=self.pk, + vcredentials__status=VerificableCredential.Status.ISSUED + ) self.object.delete() return redirect('idhub:admin_schemas') diff --git a/idhub/models.py b/idhub/models.py index f1eea85..38f926f 100644 --- a/idhub/models.py +++ b/idhub/models.py @@ -527,6 +527,11 @@ class Schemas(models.Model): return name + @property + def has_credentials(self, request=None): + return self.vcredentials.filter( + status=VerificableCredential.Status.ISSUED).exists() + def _get_language_code(self, request=None): language_code = settings.LANGUAGE_CODE if request: diff --git a/idhub/templates/idhub/admin/schemas.html b/idhub/templates/idhub/admin/schemas.html index 543c89b..6b0e816 100644 --- a/idhub/templates/idhub/admin/schemas.html +++ b/idhub/templates/idhub/admin/schemas.html @@ -13,6 +13,7 @@ {% for schema in object_list %} +{% if not schema.has_credentials %} +{% endif %} {% endfor %} {% endblock %}