label_token #8
|
@ -1,11 +1,12 @@
|
||||||
import django_tables2 as tables
|
import django_tables2 as tables
|
||||||
from django.utils.html import format_html
|
from django.utils.html import format_html
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
from django.urls import reverse
|
||||||
|
|
||||||
from webhook.models import Token
|
from webhook.models import Token
|
||||||
|
|
||||||
|
|
||||||
class ButtonColumn(tables.Column):
|
class ButtonRemoveColumn(tables.Column):
|
||||||
attrs = {
|
attrs = {
|
||||||
"a": {
|
"a": {
|
||||||
"type": "button",
|
"type": "button",
|
||||||
|
@ -25,7 +26,7 @@ class ButtonColumn(tables.Column):
|
||||||
|
|
||||||
|
|
||||||
class TokensTable(tables.Table):
|
class TokensTable(tables.Table):
|
||||||
delete = ButtonColumn(
|
delete = ButtonRemoveColumn(
|
||||||
verbose_name=_("Delete"),
|
verbose_name=_("Delete"),
|
||||||
linkify={
|
linkify={
|
||||||
"viewname": "webhook:delete_token",
|
"viewname": "webhook:delete_token",
|
||||||
|
@ -33,11 +34,18 @@ class TokensTable(tables.Table):
|
||||||
},
|
},
|
||||||
orderable=False
|
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=())
|
token = tables.Column(verbose_name=_("Token"), empty_values=())
|
||||||
|
|
||||||
def render_view_user(self):
|
# def render_view_user(self):
|
||||||
return format_html('<i class="bi bi-eye"></i>')
|
# return format_html('<i class="bi bi-eye"></i>')
|
||||||
|
|
||||||
# def render_token(self, record):
|
# def render_token(self, record):
|
||||||
# return record.get_memberships()
|
# return record.get_memberships()
|
||||||
|
@ -63,5 +71,14 @@ class TokensTable(tables.Table):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Token
|
model = Token
|
||||||
template_name = "idhub/custom_table.html"
|
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('<i class="bi bi-toggle-on text-primary"></i>')
|
||||||
|
else: # if `active` is False
|
||||||
|
return format_html('<i class="bi bi-toggle-off text-danger"></i>')
|
||||||
|
|
|
@ -11,4 +11,5 @@ urlpatterns = [
|
||||||
path('tokens/', views.WebHookTokenView.as_view(), name='tokens'),
|
path('tokens/', views.WebHookTokenView.as_view(), name='tokens'),
|
||||||
path('tokens/new', views.TokenNewView.as_view(), name='new_token'),
|
path('tokens/new', views.TokenNewView.as_view(), name='new_token'),
|
||||||
path('tokens/<int:pk>/del', views.TokenDeleteView.as_view(), name='delete_token'),
|
path('tokens/<int:pk>/del', views.TokenDeleteView.as_view(), name='delete_token'),
|
||||||
|
path('tokens/<int:pk>/status', views.TokenStatusView.as_view(), name='status_token'),
|
||||||
]
|
]
|
||||||
|
|
|
@ -153,6 +153,22 @@ class TokenDeleteView(AdminView, DeleteView):
|
||||||
return redirect('webhook:tokens')
|
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):
|
class TokenNewView(AdminView, View):
|
||||||
|
|
||||||
def get(self, request, *args, **kwargs):
|
def get(self, request, *args, **kwargs):
|
||||||
|
|
Loading…
Reference in a new issue