From c55db2495424b56091bed085cc64c777f2647fae Mon Sep 17 00:00:00 2001 From: Elijah Date: Fri, 15 Dec 2023 18:40:56 +0100 Subject: [PATCH] Fixed templates and data admin tables --- idhub/admin/tables.py | 28 ++++++++++++++++- idhub/admin/views.py | 19 ++++++----- idhub/templates/idhub/admin/import.html | 30 ++---------------- idhub/templates/idhub/admin/schemas.html | 40 ++++-------------------- 4 files changed, 47 insertions(+), 70 deletions(-) diff --git a/idhub/admin/tables.py b/idhub/admin/tables.py index ce19c48..a95ad63 100644 --- a/idhub/admin/tables.py +++ b/idhub/admin/tables.py @@ -7,7 +7,8 @@ from idhub.models import ( Service, VerificableCredential, DID, - File_datas + File_datas, + Schemas ) from idhub_auth.models import User @@ -216,3 +217,28 @@ class DataTable(tables.Table): model = File_datas template_name = "idhub/custom_table.html" fields = ("created_at", "file_name", "success") + + +class TemplateTable(tables.Table): + view_schema = ButtonColumn( + linkify={ + "viewname": "idhub:admin_schemas_download", + "args": [tables.A("pk")] + }, + orderable=False + ) + delete_template_code = """""" + delete_schema = tables.TemplateColumn(template_code=delete_template_code, + orderable=False, + verbose_name="Delete schema") + + class Meta: + model = Schemas + template_name = "idhub/custom_table.html" + fields = ("created_at", "file_schema", "name", "description", + "view_schema", "delete_schema") diff --git a/idhub/admin/views.py b/idhub/admin/views.py index cd82a3a..255f5ab 100644 --- a/idhub/admin/views.py +++ b/idhub/admin/views.py @@ -38,7 +38,8 @@ from idhub.admin.tables import ( ServicesTable, CredentialTable, DIDTable, - DataTable + DataTable, + TemplateTable ) from idhub.models import ( DID, @@ -730,19 +731,21 @@ class WalletConfigIssuesView(Credentials): wallet = True -class SchemasView(SchemasMix): +class SchemasView(SchemasMix, SingleTableView): template_name = "idhub/admin/schemas.html" + table_class = TemplateTable subtitle = _('View credential templates') icon = '' + model = Schemas def get_context_data(self, **kwargs): - context = super().get_context_data(**kwargs) - context.update({ - 'schemas': Schemas.objects, - }) - return context + queryset = kwargs.pop('object_list', None) + if queryset is None: + self.object_list = self.model.objects.all() + + return super().get_context_data(**kwargs) + - class SchemasDeleteView(SchemasMix): def get(self, request, *args, **kwargs): diff --git a/idhub/templates/idhub/admin/import.html b/idhub/templates/idhub/admin/import.html index 6c280e4..87c0cc3 100644 --- a/idhub/templates/idhub/admin/import.html +++ b/idhub/templates/idhub/admin/import.html @@ -7,32 +7,8 @@ {{ subtitle }} -
-
- {% render_table table %} -
- - - - - - - - - - {% for f in dates.all %} - - - - - - {% endfor %} - -
{{ f.created_at }}{{ f.file_name }}{% if f.success %}{% else %}{% endif %}
- -
-
+{% render_table table %} + {% endblock %} diff --git a/idhub/templates/idhub/admin/schemas.html b/idhub/templates/idhub/admin/schemas.html index 6afcf41..543c89b 100644 --- a/idhub/templates/idhub/admin/schemas.html +++ b/idhub/templates/idhub/admin/schemas.html @@ -1,47 +1,19 @@ {% extends "idhub/base_admin.html" %} {% load i18n %} +{% load render_table from django_tables2 %} {% block content %}

{{ subtitle }}

-
-
-
- - - - - - - - - - - - - {% for schema in schemas.all %} - - - - - - - - - {% endfor %} - -
{{ schema.created_at }}{{ schema.file_schema }}{{ schema.name }}{{ schema.description }}
- -
-
+{% render_table table %} + -{% for schema in schemas.all %} -