Merge pull request 'remove-schemas' (#159) from remove-schemas into release

Reviewed-on: https://gitea.pangea.org/trustchain-oc1-orchestral/IdHub/pulls/159
This commit is contained in:
cayop 2024-03-01 08:38:46 +00:00
commit 0460ce6bce
4 changed files with 20 additions and 2 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,
@ -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"

View file

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

View file

@ -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:

View file

@ -13,6 +13,7 @@
</div>
<!-- Modal -->
{% for schema in object_list %}
{% if not schema.has_credentials %}
<div class="modal" id="confirm-delete-{{ schema.id }}" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
@ -30,5 +31,6 @@
</div>
</div>
</div>
{% endif %}
{% endfor %}
{% endblock %}