mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
* Introduce the isodate(), isotime(), and isodatetime() template filters * Display the relative time on mouse hover * Render journal entry times in ISO 8601 format * Use ISO 8601 format when displaying dates & times in a table * Standardize the use of DateTimeColumn across all tables
58 lines
1.4 KiB
Python
58 lines
1.4 KiB
Python
from django.utils.translation import gettext as _
|
|
|
|
from account.models import UserToken
|
|
from netbox.tables import NetBoxTable, columns
|
|
|
|
__all__ = (
|
|
'UserTokenTable',
|
|
)
|
|
|
|
|
|
TOKEN = """<samp><span id="token_{{ record.pk }}">{{ record }}</span></samp>"""
|
|
|
|
ALLOWED_IPS = """{{ value|join:", " }}"""
|
|
|
|
COPY_BUTTON = """
|
|
{% if settings.ALLOW_TOKEN_RETRIEVAL %}
|
|
{% copy_content record.pk prefix="token_" color="success" %}
|
|
{% endif %}
|
|
"""
|
|
|
|
|
|
class UserTokenTable(NetBoxTable):
|
|
"""
|
|
Table for users to manager their own API tokens under account views.
|
|
"""
|
|
key = columns.TemplateColumn(
|
|
verbose_name=_('Key'),
|
|
template_code=TOKEN,
|
|
)
|
|
write_enabled = columns.BooleanColumn(
|
|
verbose_name=_('Write Enabled')
|
|
)
|
|
created = columns.DateTimeColumn(
|
|
timespec='minutes',
|
|
verbose_name=_('Created'),
|
|
)
|
|
expires = columns.DateTimeColumn(
|
|
timespec='minutes',
|
|
verbose_name=_('Expires'),
|
|
)
|
|
last_used = columns.DateTimeColumn(
|
|
verbose_name=_('Last Used'),
|
|
)
|
|
allowed_ips = columns.TemplateColumn(
|
|
verbose_name=_('Allowed IPs'),
|
|
template_code=ALLOWED_IPS
|
|
)
|
|
actions = columns.ActionsColumn(
|
|
actions=('edit', 'delete'),
|
|
extra_buttons=COPY_BUTTON
|
|
)
|
|
|
|
class Meta(NetBoxTable.Meta):
|
|
model = UserToken
|
|
fields = (
|
|
'pk', 'id', 'key', 'description', 'write_enabled', 'created', 'expires', 'last_used', 'allowed_ips',
|
|
)
|