diff --git a/idhub/admin/tables.py b/idhub/admin/tables.py index 74dcc6f..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, @@ -253,6 +253,13 @@ class TemplateTable(tables.Table): return (queryset, True) + def render_delete_schema(self, value, record): + if not record.has_credentials: + tmpl = self.delete_template_code.format(record.id) + return format_html(tmpl) + else: + return "" + class Meta: model = Schemas template_name = "idhub/custom_table.html" diff --git a/idhub/admin/views.py b/idhub/admin/views.py index e2dd58f..a030f99 100644 --- a/idhub/admin/views.py +++ b/idhub/admin/views.py @@ -870,7 +870,11 @@ 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) + issued = VerificableCredential.Status.ISSUED + self.object = get_object_or_404( + Schemas.objects.exclude(vcredentials__status=issued), + pk=self.pk, + ) self.object.delete() return redirect('idhub:admin_schemas') diff --git a/idhub/models.py b/idhub/models.py index cc77874..1072e26 100644 --- a/idhub/models.py +++ b/idhub/models.py @@ -527,6 +527,11 @@ class Schemas(models.Model): return name + @property + def has_credentials(self): + 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 %}