diff --git a/webhook/migrations/0002_token_active_token_label.py b/webhook/migrations/0002_token_active_token_label.py new file mode 100644 index 0000000..149ce7a --- /dev/null +++ b/webhook/migrations/0002_token_active_token_label.py @@ -0,0 +1,22 @@ +# Generated by Django 4.2.5 on 2025-01-27 09:20 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ('webhook', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='token', + name='active', + field=models.BooleanField(default=True, verbose_name='Active'), + ), + migrations.AddField( + model_name='token', + name='label', + field=models.CharField(default='', max_length=250, verbose_name='Label'), + ), + ] diff --git a/webhook/models.py b/webhook/models.py index 54218c2..04e6109 100644 --- a/webhook/models.py +++ b/webhook/models.py @@ -1,7 +1,10 @@ from django.db import models +from django.utils.translation import gettext_lazy as _ # Create your models here. class Token(models.Model): token = models.UUIDField() + label = models.CharField(_("Label"), max_length=250, default="") + active = models.BooleanField(_("Active"), default=True) diff --git a/webhook/tables.py b/webhook/tables.py index 498a38e..981e1ce 100644 --- a/webhook/tables.py +++ b/webhook/tables.py @@ -1,11 +1,12 @@ import django_tables2 as tables from django.utils.html import format_html from django.utils.translation import gettext_lazy as _ +from django.urls import reverse from webhook.models import Token - -class ButtonColumn(tables.Column): + +class ButtonRemoveColumn(tables.Column): attrs = { "a": { "type": "button", @@ -25,7 +26,7 @@ class ButtonColumn(tables.Column): class TokensTable(tables.Table): - delete = ButtonColumn( + delete = ButtonRemoveColumn( verbose_name=_("Delete"), linkify={ "viewname": "webhook:delete_token", @@ -33,11 +34,19 @@ class TokensTable(tables.Table): }, orderable=False ) + # active = tables.Column(linkify=lambda record: reverse("webhook:status_token", kwargs={"pk": record.pk})) + active = tables.Column( + linkify={ + "viewname": "webhook:status_token", + "args": [tables.A("pk")] + } + ) token = tables.Column(verbose_name=_("Token"), empty_values=()) + label = tables.Column(verbose_name=_("Label"), empty_values=()) - def render_view_user(self): - return format_html('') + # def render_view_user(self): + # return format_html('') # def render_token(self, record): # return record.get_memberships() @@ -63,5 +72,13 @@ class TokensTable(tables.Table): class Meta: model = Token template_name = "idhub/custom_table.html" - fields = ("token", "view_user") + fields = ("token", "label", "active") + def render_active(self, value): + """ + Render icons custom based on active value + """ + if value: # if `active` is True + return format_html('') + else: # if `active` is False + return format_html('') diff --git a/webhook/templates/new_token.html b/webhook/templates/new_token.html new file mode 100644 index 0000000..03355c1 --- /dev/null +++ b/webhook/templates/new_token.html @@ -0,0 +1,34 @@ +{% extends "idhub/base_admin.html" %} +{% load i18n %} + +{% block content %} +