fix delete schemas

This commit is contained in:
Cayo Puigdefabregas 2024-03-01 09:31:43 +01:00
parent 156b0b4586
commit 55355f9e69
3 changed files with 7 additions and 6 deletions

View file

@ -229,7 +229,7 @@ class TemplateTable(tables.Table):
delete_template_code = """<a class="text-danger"
href="javascript:void()"
data-bs-toggle="modal"
data-bs-target="#confirm-delete-{{ record.id }}"
data-bs-target="#confirm-delete-{}"
title="Remove"
><i class="bi bi-trash"></i></a>"""
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 ""

View file

@ -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()

View file

@ -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()