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" delete_template_code = """<a class="text-danger"
href="javascript:void()" href="javascript:void()"
data-bs-toggle="modal" data-bs-toggle="modal"
data-bs-target="#confirm-delete-{{ record.id }}" data-bs-target="#confirm-delete-{}"
title="Remove" title="Remove"
><i class="bi bi-trash"></i></a>""" ><i class="bi bi-trash"></i></a>"""
delete_schema = tables.TemplateColumn(template_code=delete_template_code, delete_schema = tables.TemplateColumn(template_code=delete_template_code,
@ -254,8 +254,9 @@ class TemplateTable(tables.Table):
return (queryset, True) return (queryset, True)
def render_delete_schema(self, value, record): def render_delete_schema(self, value, record):
if record.has_credentials(): if not record.has_credentials:
return value tmpl = self.delete_template_code.format(record.id)
return format_html(tmpl)
else: else:
return "" return ""

View File

@ -870,10 +870,10 @@ class SchemasDeleteView(SchemasMix):
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
self.check_valid_user() self.check_valid_user()
self.pk = kwargs['pk'] self.pk = kwargs['pk']
issued = VerificableCredential.Status.ISSUED
self.object = get_object_or_404( self.object = get_object_or_404(
Schemas, Schemas.objects.exclude(vcredentials__status=issued),
pk=self.pk, pk=self.pk,
vcredentials__status=VerificableCredential.Status.ISSUED
) )
self.object.delete() self.object.delete()

View File

@ -528,7 +528,7 @@ class Schemas(models.Model):
return name return name
@property @property
def has_credentials(self, request=None): def has_credentials(self):
return self.vcredentials.filter( return self.vcredentials.filter(
status=VerificableCredential.Status.ISSUED).exists() status=VerificableCredential.Status.ISSUED).exists()