From 644edab35a880c6b662d5abada27bc6d3e538934 Mon Sep 17 00:00:00 2001 From: Elijah Date: Wed, 3 Jan 2024 19:10:20 +0100 Subject: [PATCH] Fixed bug of template management columns giving error on sort --- idhub/admin/tables.py | 10 +++ ...n_schemas_name_alter_did_label_and_more.py | 87 +++++++++++++++++++ idhub/models.py | 6 +- 3 files changed, 101 insertions(+), 2 deletions(-) create mode 100644 idhub/migrations/0002_schemas_description_schemas_name_alter_did_label_and_more.py diff --git a/idhub/admin/tables.py b/idhub/admin/tables.py index 6fa3c86..2c6e89e 100644 --- a/idhub/admin/tables.py +++ b/idhub/admin/tables.py @@ -245,6 +245,16 @@ class TemplateTable(tables.Table): orderable=False, verbose_name="Delete schema") + # empty_values makes django_tables call render_attr + name = tables.Column(empty_values=()) + description = tables.Column(empty_values=()) + + def render_name(self, record): + return record.get_name() + + def render_description(self, record): + return record.get_description() + class Meta: model = Schemas template_name = "idhub/custom_table.html" diff --git a/idhub/migrations/0002_schemas_description_schemas_name_alter_did_label_and_more.py b/idhub/migrations/0002_schemas_description_schemas_name_alter_did_label_and_more.py new file mode 100644 index 0000000..cadd82d --- /dev/null +++ b/idhub/migrations/0002_schemas_description_schemas_name_alter_did_label_and_more.py @@ -0,0 +1,87 @@ +# Generated by Django 4.2.5 on 2024-01-03 18:04 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + dependencies = [ + ('idhub', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='schemas', + name='description', + field=models.CharField(max_length=250, null=True), + ), + migrations.AddField( + model_name='schemas', + name='name', + field=models.CharField(max_length=250, null=True), + ), + migrations.AlterField( + model_name='did', + name='label', + field=models.CharField(max_length=50, verbose_name='Label'), + ), + migrations.AlterField( + model_name='event', + name='created', + field=models.DateTimeField(auto_now=True, verbose_name='Date'), + ), + migrations.AlterField( + model_name='event', + name='message', + field=models.CharField(max_length=350, verbose_name='Description'), + ), + migrations.AlterField( + model_name='event', + name='type', + field=models.PositiveSmallIntegerField( + choices=[ + (1, 'User registered'), + (2, 'User welcomed'), + (3, 'Data update requested by user'), + (4, 'Data update requested. Pending approval by administrator'), + (5, "User's data updated by admin"), + (6, 'Your data updated by admin'), + (7, 'User deactivated by admin'), + (8, 'DID created by user'), + (9, 'DID created'), + (10, 'DID deleted'), + (11, 'Credential deleted by user'), + (12, 'Credential deleted'), + (13, 'Credential issued for user'), + (14, 'Credential issued'), + (15, 'Credential presented by user'), + (16, 'Credential presented'), + (17, 'Credential enabled'), + (18, 'Credential available'), + (19, 'Credential revoked by admin'), + (20, 'Credential revoked'), + (21, 'Role created by admin'), + (22, 'Role modified by admin'), + (23, 'Role deleted by admin'), + (24, 'Service created by admin'), + (25, 'Service modified by admin'), + (26, 'Service deleted by admin'), + (27, 'Organisational DID created by admin'), + (28, 'Organisational DID deleted by admin'), + (29, 'User deactivated'), + (30, 'User activated'), + ], + verbose_name='Event', + ), + ), + migrations.AlterField( + model_name='userrol', + name='service', + field=models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + related_name='users', + to='idhub.service', + verbose_name='Service', + ), + ), + ] diff --git a/idhub/models.py b/idhub/models.py index 7d1ef6c..3ef0269 100644 --- a/idhub/models.py +++ b/idhub/models.py @@ -436,6 +436,8 @@ class Schemas(models.Model): file_schema = models.CharField(max_length=250) data = models.TextField() created_at = models.DateTimeField(auto_now=True) + name = models.CharField(max_length=250, null=True) + description = models.CharField(max_length=250, null=True) @property def get_schema(self): @@ -443,10 +445,10 @@ class Schemas(models.Model): return {} return json.loads(self.data) - def name(self): + def get_name(self): return self.get_schema.get('name', '') - def description(self): + def get_description(self): return self.get_schema.get('description', '')