From 55355f9e6984d591177b53325347737befbf917b Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Fri, 1 Mar 2024 09:31:43 +0100 Subject: [PATCH] fix delete schemas --- idhub/admin/tables.py | 7 ++++--- idhub/admin/views.py | 4 ++-- idhub/models.py | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/idhub/admin/tables.py b/idhub/admin/tables.py index 0fcb58e..51df7e8 100644 --- a/idhub/admin/tables.py +++ b/idhub/admin/tables.py @@ -229,7 +229,7 @@ class TemplateTable(tables.Table): delete_template_code = """""" delete_schema = tables.TemplateColumn(template_code=delete_template_code, @@ -254,8 +254,9 @@ class TemplateTable(tables.Table): return (queryset, True) def render_delete_schema(self, value, record): - if record.has_credentials(): - return value + if not record.has_credentials: + tmpl = self.delete_template_code.format(record.id) + return format_html(tmpl) else: return "" diff --git a/idhub/admin/views.py b/idhub/admin/views.py index b50f2d2..a030f99 100644 --- a/idhub/admin/views.py +++ b/idhub/admin/views.py @@ -870,10 +870,10 @@ class SchemasDeleteView(SchemasMix): def get(self, request, *args, **kwargs): self.check_valid_user() self.pk = kwargs['pk'] + issued = VerificableCredential.Status.ISSUED self.object = get_object_or_404( - Schemas, + Schemas.objects.exclude(vcredentials__status=issued), pk=self.pk, - vcredentials__status=VerificableCredential.Status.ISSUED ) self.object.delete() diff --git a/idhub/models.py b/idhub/models.py index 38f926f..db8522f 100644 --- a/idhub/models.py +++ b/idhub/models.py @@ -528,7 +528,7 @@ class Schemas(models.Model): return name @property - def has_credentials(self, request=None): + def has_credentials(self): return self.vcredentials.filter( status=VerificableCredential.Status.ISSUED).exists()