diff --git a/webhook/tables.py b/webhook/tables.py
index 498a38e..06809ea 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,18 @@ 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=())
- 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 +71,14 @@ class TokensTable(tables.Table):
class Meta:
model = Token
template_name = "idhub/custom_table.html"
- fields = ("token", "view_user")
+ fields = ("token", "lavel", "active")
+ def render_active(self, value):
+ """
+ Render icons custom based on active value
+ """
+ # import pdb; pdb.set_trace()
+ if value: # if `active` is True
+ return format_html('')
+ else: # if `active` is False
+ return format_html('')
diff --git a/webhook/urls.py b/webhook/urls.py
index c2d4bd2..b193264 100644
--- a/webhook/urls.py
+++ b/webhook/urls.py
@@ -11,4 +11,5 @@ urlpatterns = [
path('tokens/', views.WebHookTokenView.as_view(), name='tokens'),
path('tokens/new', views.TokenNewView.as_view(), name='new_token'),
path('tokens//del', views.TokenDeleteView.as_view(), name='delete_token'),
+ path('tokens//status', views.TokenStatusView.as_view(), name='status_token'),
]
diff --git a/webhook/views.py b/webhook/views.py
index 71625d7..50f0b72 100644
--- a/webhook/views.py
+++ b/webhook/views.py
@@ -142,6 +142,22 @@ class TokenDeleteView(AdminView, DeleteView):
return redirect('webhook:tokens')
+class TokenStatusView(AdminView, DeleteView):
+ model = Token
+
+ def get(self, request, *args, **kwargs):
+ self.check_valid_user()
+ self.pk = kwargs['pk']
+ self.object = get_object_or_404(self.model, pk=self.pk)
+ if self.object.active:
+ self.object.active = False
+ else:
+ self.object.active = True
+ self.object.save()
+
+ return redirect('webhook:tokens')
+
+
class TokenNewView(AdminView, View):
def get(self, request, *args, **kwargs):