mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-25 08:46:10 -06:00
13150 translate table column fields
This commit is contained in:
parent
96ea0ac9c7
commit
ec4b5d625c
@ -1,3 +1,4 @@
|
|||||||
|
from django.utils.translation import gettext_lazy as _
|
||||||
import django_tables2 as tables
|
import django_tables2 as tables
|
||||||
|
|
||||||
from circuits.models import *
|
from circuits.models import *
|
||||||
@ -24,7 +25,8 @@ CIRCUITTERMINATION_LINK = """
|
|||||||
|
|
||||||
class CircuitTypeTable(NetBoxTable):
|
class CircuitTypeTable(NetBoxTable):
|
||||||
name = tables.Column(
|
name = tables.Column(
|
||||||
linkify=True
|
linkify=True,
|
||||||
|
verbose_name=_('Name'),
|
||||||
)
|
)
|
||||||
tags = columns.TagColumn(
|
tags = columns.TagColumn(
|
||||||
url_name='circuits:circuittype_list'
|
url_name='circuits:circuittype_list'
|
||||||
@ -32,7 +34,7 @@ class CircuitTypeTable(NetBoxTable):
|
|||||||
circuit_count = columns.LinkedCountColumn(
|
circuit_count = columns.LinkedCountColumn(
|
||||||
viewname='circuits:circuit_list',
|
viewname='circuits:circuit_list',
|
||||||
url_params={'type_id': 'pk'},
|
url_params={'type_id': 'pk'},
|
||||||
verbose_name='Circuits'
|
verbose_name=_('Circuits')
|
||||||
)
|
)
|
||||||
|
|
||||||
class Meta(NetBoxTable.Meta):
|
class Meta(NetBoxTable.Meta):
|
||||||
@ -46,28 +48,31 @@ class CircuitTypeTable(NetBoxTable):
|
|||||||
class CircuitTable(TenancyColumnsMixin, ContactsColumnMixin, NetBoxTable):
|
class CircuitTable(TenancyColumnsMixin, ContactsColumnMixin, NetBoxTable):
|
||||||
cid = tables.Column(
|
cid = tables.Column(
|
||||||
linkify=True,
|
linkify=True,
|
||||||
verbose_name='Circuit ID'
|
verbose_name=_('Circuit ID')
|
||||||
)
|
)
|
||||||
provider = tables.Column(
|
provider = tables.Column(
|
||||||
|
verbose_name=_('Provider'),
|
||||||
linkify=True
|
linkify=True
|
||||||
)
|
)
|
||||||
provider_account = tables.Column(
|
provider_account = tables.Column(
|
||||||
linkify=True,
|
linkify=True,
|
||||||
verbose_name='Account'
|
verbose_name=_('Account')
|
||||||
)
|
)
|
||||||
status = columns.ChoiceFieldColumn()
|
status = columns.ChoiceFieldColumn()
|
||||||
termination_a = tables.TemplateColumn(
|
termination_a = tables.TemplateColumn(
|
||||||
template_code=CIRCUITTERMINATION_LINK,
|
template_code=CIRCUITTERMINATION_LINK,
|
||||||
verbose_name='Side A'
|
verbose_name=_('Side A')
|
||||||
)
|
)
|
||||||
termination_z = tables.TemplateColumn(
|
termination_z = tables.TemplateColumn(
|
||||||
template_code=CIRCUITTERMINATION_LINK,
|
template_code=CIRCUITTERMINATION_LINK,
|
||||||
verbose_name='Side Z'
|
verbose_name=_('Side Z')
|
||||||
)
|
)
|
||||||
commit_rate = CommitRateColumn(
|
commit_rate = CommitRateColumn(
|
||||||
verbose_name='Commit Rate'
|
verbose_name=_('Commit Rate')
|
||||||
|
)
|
||||||
|
comments = columns.MarkdownColumn(
|
||||||
|
verbose_name=_('Comments'),
|
||||||
)
|
)
|
||||||
comments = columns.MarkdownColumn()
|
|
||||||
tags = columns.TagColumn(
|
tags = columns.TagColumn(
|
||||||
url_name='circuits:circuit_list'
|
url_name='circuits:circuit_list'
|
||||||
)
|
)
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import django_tables2 as tables
|
import django_tables2 as tables
|
||||||
|
from django.utils.translation import gettext_lazy as _
|
||||||
from circuits.models import *
|
from circuits.models import *
|
||||||
from django_tables2.utils import Accessor
|
from django_tables2.utils import Accessor
|
||||||
from tenancy.tables import ContactsColumnMixin
|
from tenancy.tables import ContactsColumnMixin
|
||||||
@ -14,35 +15,38 @@ __all__ = (
|
|||||||
|
|
||||||
class ProviderTable(ContactsColumnMixin, NetBoxTable):
|
class ProviderTable(ContactsColumnMixin, NetBoxTable):
|
||||||
name = tables.Column(
|
name = tables.Column(
|
||||||
|
verbose_name=_('Name'),
|
||||||
linkify=True
|
linkify=True
|
||||||
)
|
)
|
||||||
accounts = columns.ManyToManyColumn(
|
accounts = columns.ManyToManyColumn(
|
||||||
linkify_item=True,
|
linkify_item=True,
|
||||||
verbose_name='Accounts'
|
verbose_name=_('Accounts')
|
||||||
)
|
)
|
||||||
account_count = columns.LinkedCountColumn(
|
account_count = columns.LinkedCountColumn(
|
||||||
accessor=tables.A('accounts__count'),
|
accessor=tables.A('accounts__count'),
|
||||||
viewname='circuits:provideraccount_list',
|
viewname='circuits:provideraccount_list',
|
||||||
url_params={'account_id': 'pk'},
|
url_params={'account_id': 'pk'},
|
||||||
verbose_name='Account Count'
|
verbose_name=_('Account Count')
|
||||||
)
|
)
|
||||||
asns = columns.ManyToManyColumn(
|
asns = columns.ManyToManyColumn(
|
||||||
linkify_item=True,
|
linkify_item=True,
|
||||||
verbose_name='ASNs'
|
verbose_name=_('ASNs')
|
||||||
)
|
)
|
||||||
asn_count = columns.LinkedCountColumn(
|
asn_count = columns.LinkedCountColumn(
|
||||||
accessor=tables.A('asns__count'),
|
accessor=tables.A('asns__count'),
|
||||||
viewname='ipam:asn_list',
|
viewname='ipam:asn_list',
|
||||||
url_params={'provider_id': 'pk'},
|
url_params={'provider_id': 'pk'},
|
||||||
verbose_name='ASN Count'
|
verbose_name=_('ASN Count')
|
||||||
)
|
)
|
||||||
circuit_count = columns.LinkedCountColumn(
|
circuit_count = columns.LinkedCountColumn(
|
||||||
accessor=Accessor('count_circuits'),
|
accessor=Accessor('count_circuits'),
|
||||||
viewname='circuits:circuit_list',
|
viewname='circuits:circuit_list',
|
||||||
url_params={'provider_id': 'pk'},
|
url_params={'provider_id': 'pk'},
|
||||||
verbose_name='Circuits'
|
verbose_name=_('Circuits')
|
||||||
|
)
|
||||||
|
comments = columns.MarkdownColumn(
|
||||||
|
verbose_name=_('Comments'),
|
||||||
)
|
)
|
||||||
comments = columns.MarkdownColumn()
|
|
||||||
tags = columns.TagColumn(
|
tags = columns.TagColumn(
|
||||||
url_name='circuits:provider_list'
|
url_name='circuits:provider_list'
|
||||||
)
|
)
|
||||||
@ -58,19 +62,25 @@ class ProviderTable(ContactsColumnMixin, NetBoxTable):
|
|||||||
|
|
||||||
class ProviderAccountTable(ContactsColumnMixin, NetBoxTable):
|
class ProviderAccountTable(ContactsColumnMixin, NetBoxTable):
|
||||||
account = tables.Column(
|
account = tables.Column(
|
||||||
linkify=True
|
linkify=True,
|
||||||
|
verbose_name=_('Account'),
|
||||||
|
)
|
||||||
|
name = tables.Column(
|
||||||
|
verbose_name=_('Name'),
|
||||||
)
|
)
|
||||||
name = tables.Column()
|
|
||||||
provider = tables.Column(
|
provider = tables.Column(
|
||||||
|
verbose_name=_('Provider'),
|
||||||
linkify=True
|
linkify=True
|
||||||
)
|
)
|
||||||
circuit_count = columns.LinkedCountColumn(
|
circuit_count = columns.LinkedCountColumn(
|
||||||
accessor=Accessor('count_circuits'),
|
accessor=Accessor('count_circuits'),
|
||||||
viewname='circuits:circuit_list',
|
viewname='circuits:circuit_list',
|
||||||
url_params={'provider_account_id': 'pk'},
|
url_params={'provider_account_id': 'pk'},
|
||||||
verbose_name='Circuits'
|
verbose_name=_('Circuits')
|
||||||
|
)
|
||||||
|
comments = columns.MarkdownColumn(
|
||||||
|
verbose_name=_('Comments'),
|
||||||
)
|
)
|
||||||
comments = columns.MarkdownColumn()
|
|
||||||
tags = columns.TagColumn(
|
tags = columns.TagColumn(
|
||||||
url_name='circuits:provideraccount_list'
|
url_name='circuits:provideraccount_list'
|
||||||
)
|
)
|
||||||
@ -86,12 +96,16 @@ class ProviderAccountTable(ContactsColumnMixin, NetBoxTable):
|
|||||||
|
|
||||||
class ProviderNetworkTable(NetBoxTable):
|
class ProviderNetworkTable(NetBoxTable):
|
||||||
name = tables.Column(
|
name = tables.Column(
|
||||||
|
verbose_name=_('Name'),
|
||||||
linkify=True
|
linkify=True
|
||||||
)
|
)
|
||||||
provider = tables.Column(
|
provider = tables.Column(
|
||||||
|
verbose_name=_('Provider'),
|
||||||
linkify=True
|
linkify=True
|
||||||
)
|
)
|
||||||
comments = columns.MarkdownColumn()
|
comments = columns.MarkdownColumn(
|
||||||
|
verbose_name=_('Comments'),
|
||||||
|
)
|
||||||
tags = columns.TagColumn(
|
tags = columns.TagColumn(
|
||||||
url_name='circuits:providernetwork_list'
|
url_name='circuits:providernetwork_list'
|
||||||
)
|
)
|
||||||
|
@ -12,6 +12,7 @@ from django.utils.dateparse import parse_date
|
|||||||
from django.utils.html import escape
|
from django.utils.html import escape
|
||||||
from django.utils.formats import date_format
|
from django.utils.formats import date_format
|
||||||
from django.utils.safestring import mark_safe
|
from django.utils.safestring import mark_safe
|
||||||
|
from django.utils.translation import gettext_lazy as _
|
||||||
from django_tables2.columns import library
|
from django_tables2.columns import library
|
||||||
from django_tables2.utils import Accessor
|
from django_tables2.utils import Accessor
|
||||||
|
|
||||||
@ -168,7 +169,7 @@ class ToggleColumn(tables.CheckBoxColumn):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def header(self):
|
def header(self):
|
||||||
return mark_safe('<input type="checkbox" class="toggle form-check-input" title="Toggle All" />')
|
return mark_safe('<input type="checkbox" class="toggle form-check-input" title=_("Toggle All") />')
|
||||||
|
|
||||||
|
|
||||||
class BooleanColumn(tables.Column):
|
class BooleanColumn(tables.Column):
|
||||||
@ -269,12 +270,13 @@ class ActionsColumn(tables.Column):
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Create the actions dropdown menu
|
# Create the actions dropdown menu
|
||||||
|
toggle_text = _('Toggle Dropdown')
|
||||||
if button and dropdown_links:
|
if button and dropdown_links:
|
||||||
html += (
|
html += (
|
||||||
f'<span class="btn-group dropdown">'
|
f'<span class="btn-group dropdown">'
|
||||||
f' {button}'
|
f' {button}'
|
||||||
f' <a class="btn btn-sm btn-{dropdown_class} dropdown-toggle" type="button" data-bs-toggle="dropdown" style="padding-left: 2px">'
|
f' <a class="btn btn-sm btn-{dropdown_class} dropdown-toggle" type="button" data-bs-toggle="dropdown" style="padding-left: 2px">'
|
||||||
f' <span class="visually-hidden">Toggle Dropdown</span></a>'
|
f' <span class="visually-hidden">{toggle_text}</span></a>'
|
||||||
f' <ul class="dropdown-menu">{"".join(dropdown_links)}</ul>'
|
f' <ul class="dropdown-menu">{"".join(dropdown_links)}</ul>'
|
||||||
f'</span>'
|
f'</span>'
|
||||||
)
|
)
|
||||||
@ -284,7 +286,7 @@ class ActionsColumn(tables.Column):
|
|||||||
html += (
|
html += (
|
||||||
f'<span class="btn-group dropdown">'
|
f'<span class="btn-group dropdown">'
|
||||||
f' <a class="btn btn-sm btn-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown">'
|
f' <a class="btn btn-sm btn-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown">'
|
||||||
f' <span class="visually-hidden">Toggle Dropdown</span></a>'
|
f' <span class="visually-hidden">{toggle_text}</span></a>'
|
||||||
f' <ul class="dropdown-menu">{"".join(dropdown_links)}</ul>'
|
f' <ul class="dropdown-menu">{"".join(dropdown_links)}</ul>'
|
||||||
f'</span>'
|
f'</span>'
|
||||||
)
|
)
|
||||||
@ -438,7 +440,8 @@ class TagColumn(tables.TemplateColumn):
|
|||||||
super().__init__(
|
super().__init__(
|
||||||
orderable=False,
|
orderable=False,
|
||||||
template_code=self.template_code,
|
template_code=self.template_code,
|
||||||
extra_context={'url_name': url_name}
|
extra_context={'url_name': url_name},
|
||||||
|
verbose_name=_('Tags'),
|
||||||
)
|
)
|
||||||
|
|
||||||
def value(self, value):
|
def value(self, value):
|
||||||
@ -520,7 +523,8 @@ class CustomLinkColumn(tables.Column):
|
|||||||
if rendered:
|
if rendered:
|
||||||
return mark_safe(f'<a href="{rendered["link"]}"{rendered["link_target"]}>{rendered["text"]}</a>')
|
return mark_safe(f'<a href="{rendered["link"]}"{rendered["link_target"]}>{rendered["text"]}</a>')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return mark_safe(f'<span class="text-danger" title="{e}"><i class="mdi mdi-alert"></i> Error</span>')
|
error_text = _('Error')
|
||||||
|
return mark_safe(f'<span class="text-danger" title="{e}"><i class="mdi mdi-alert"></i> {error_text}</span>')
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
def value(self, record):
|
def value(self, record):
|
||||||
@ -585,9 +589,10 @@ class MarkdownColumn(tables.TemplateColumn):
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, **kwargs):
|
||||||
super().__init__(
|
super().__init__(
|
||||||
template_code=self.template_code
|
template_code=self.template_code,
|
||||||
|
**kwargs,
|
||||||
)
|
)
|
||||||
|
|
||||||
def value(self, value):
|
def value(self, value):
|
||||||
|
Loading…
Reference in New Issue
Block a user