2016-03-01 11:23:03 -05:00
|
|
|
import django_tables2 as tables
|
2017-10-20 16:27:19 -04:00
|
|
|
from django.utils.safestring import mark_safe
|
2017-11-07 11:08:23 -05:00
|
|
|
from django_tables2.utils import Accessor
|
2017-10-20 16:27:19 -04:00
|
|
|
|
2018-01-30 11:57:21 -05:00
|
|
|
from tenancy.tables import COL_TENANT
|
2017-07-12 16:42:45 -04:00
|
|
|
from utilities.tables import BaseTable, ToggleColumn
|
2016-05-13 12:44:03 -04:00
|
|
|
from .models import Circuit, CircuitType, Provider
|
|
|
|
|
2016-07-28 15:04:27 -04:00
|
|
|
CIRCUITTYPE_ACTIONS = """
|
2018-06-20 14:54:04 -04:00
|
|
|
<a href="{% url 'circuits:circuittype_changelog' slug=record.slug %}" class="btn btn-default btn-xs" title="Changelog">
|
|
|
|
<i class="fa fa-history"></i>
|
|
|
|
</a>
|
2016-05-18 15:17:58 -04:00
|
|
|
{% if perms.circuit.change_circuittype %}
|
2019-04-08 14:10:55 -04:00
|
|
|
<a href="{% url 'circuits:circuittype_edit' slug=record.slug %}?return_url={{ request.path }}" class="btn btn-xs btn-warning"><i class="glyphicon glyphicon-pencil" aria-hidden="true"></i></a>
|
2016-05-18 15:17:58 -04:00
|
|
|
{% endif %}
|
2016-05-13 12:44:03 -04:00
|
|
|
"""
|
2016-03-01 11:23:03 -05:00
|
|
|
|
2018-02-06 14:06:05 -05:00
|
|
|
STATUS_LABEL = """
|
|
|
|
<span class="label label-{{ record.get_status_class }}">{{ record.get_status_display }}</span>
|
|
|
|
"""
|
|
|
|
|
2016-03-01 11:23:03 -05:00
|
|
|
|
2017-10-20 16:27:19 -04:00
|
|
|
class CircuitTerminationColumn(tables.Column):
|
|
|
|
|
|
|
|
def render(self, value):
|
|
|
|
return mark_safe('<a href="{}">{}</a>'.format(
|
|
|
|
value.site.get_absolute_url(),
|
|
|
|
value.site
|
|
|
|
))
|
|
|
|
|
|
|
|
|
2016-03-01 11:23:03 -05:00
|
|
|
#
|
|
|
|
# Providers
|
|
|
|
#
|
|
|
|
|
2016-06-20 16:34:19 -04:00
|
|
|
class ProviderTable(BaseTable):
|
2016-06-01 13:30:33 -04:00
|
|
|
pk = ToggleColumn()
|
2017-03-29 16:05:23 -04:00
|
|
|
name = tables.LinkColumn()
|
2016-03-01 11:23:03 -05:00
|
|
|
|
2016-06-20 16:34:19 -04:00
|
|
|
class Meta(BaseTable.Meta):
|
2016-03-01 11:23:03 -05:00
|
|
|
model = Provider
|
2017-07-12 16:42:45 -04:00
|
|
|
fields = ('pk', 'name', 'asn', 'account',)
|
2016-03-01 11:23:03 -05:00
|
|
|
|
|
|
|
|
2017-07-12 16:42:45 -04:00
|
|
|
class ProviderDetailTable(ProviderTable):
|
|
|
|
circuit_count = tables.Column(accessor=Accessor('count_circuits'), verbose_name='Circuits')
|
2017-03-29 16:05:23 -04:00
|
|
|
|
2017-07-12 16:42:45 -04:00
|
|
|
class Meta(ProviderTable.Meta):
|
2017-03-29 16:05:23 -04:00
|
|
|
model = Provider
|
2017-07-12 16:42:45 -04:00
|
|
|
fields = ('pk', 'name', 'asn', 'account', 'circuit_count')
|
2017-03-29 16:05:23 -04:00
|
|
|
|
|
|
|
|
2016-05-13 12:44:03 -04:00
|
|
|
#
|
|
|
|
# Circuit types
|
|
|
|
#
|
|
|
|
|
2016-06-20 16:34:19 -04:00
|
|
|
class CircuitTypeTable(BaseTable):
|
2016-06-01 13:30:33 -04:00
|
|
|
pk = ToggleColumn()
|
2017-03-29 16:05:23 -04:00
|
|
|
name = tables.LinkColumn()
|
2016-05-13 12:44:03 -04:00
|
|
|
circuit_count = tables.Column(verbose_name='Circuits')
|
2017-03-29 16:05:23 -04:00
|
|
|
actions = tables.TemplateColumn(
|
2019-03-05 15:42:47 -06:00
|
|
|
template_code=CIRCUITTYPE_ACTIONS, attrs={'td': {'class': 'text-right noprint'}}, verbose_name=''
|
2017-03-29 16:05:23 -04:00
|
|
|
)
|
2016-05-13 12:44:03 -04:00
|
|
|
|
2016-06-20 16:34:19 -04:00
|
|
|
class Meta(BaseTable.Meta):
|
2016-05-13 12:44:03 -04:00
|
|
|
model = CircuitType
|
2016-07-28 15:04:27 -04:00
|
|
|
fields = ('pk', 'name', 'circuit_count', 'slug', 'actions')
|
2016-05-13 12:44:03 -04:00
|
|
|
|
|
|
|
|
2016-03-01 11:23:03 -05:00
|
|
|
#
|
|
|
|
# Circuits
|
|
|
|
#
|
|
|
|
|
2016-06-20 16:34:19 -04:00
|
|
|
class CircuitTable(BaseTable):
|
2016-06-01 13:30:33 -04:00
|
|
|
pk = ToggleColumn()
|
2017-03-29 16:05:23 -04:00
|
|
|
cid = tables.LinkColumn(verbose_name='ID')
|
|
|
|
provider = tables.LinkColumn('circuits:provider', args=[Accessor('provider.slug')])
|
2018-02-06 14:06:05 -05:00
|
|
|
status = tables.TemplateColumn(template_code=STATUS_LABEL, verbose_name='Status')
|
2018-01-30 11:57:21 -05:00
|
|
|
tenant = tables.TemplateColumn(template_code=COL_TENANT)
|
2017-10-20 16:27:19 -04:00
|
|
|
termination_a = CircuitTerminationColumn(orderable=False, verbose_name='A Side')
|
|
|
|
termination_z = CircuitTerminationColumn(orderable=False, verbose_name='Z Side')
|
2016-03-01 11:23:03 -05:00
|
|
|
|
2016-06-20 16:34:19 -04:00
|
|
|
class Meta(BaseTable.Meta):
|
2016-03-01 11:23:03 -05:00
|
|
|
model = Circuit
|
2018-02-06 14:06:05 -05:00
|
|
|
fields = ('pk', 'cid', 'status', 'type', 'provider', 'tenant', 'termination_a', 'termination_z', 'description')
|