diff --git a/circle/network/tables.py b/circle/network/tables.py index 3dcfa22..1882ee8 100644 --- a/circle/network/tables.py +++ b/circle/network/tables.py @@ -15,14 +15,30 @@ # You should have received a copy of the GNU General Public License along # with CIRCLE. If not, see <http://www.gnu.org/licenses/>. +from netaddr import EUI from django.utils.translation import ugettext_lazy as _ +from django.utils.html import format_html from django_tables2 import Table, A -from django_tables2.columns import LinkColumn, TemplateColumn +from django_tables2.columns import LinkColumn, TemplateColumn, Column from firewall.models import Host, Vlan, Domain, Group, Record, Rule, SwitchPort +class MACColumn(Column): + def render(self, value): + if isinstance(value, basestring): + try: + value = EUI(value) + except: + return value + try: + return format_html('<abbr title="{0}">{1}</abbr>', + value.oui.registration().org, value) + except: + return value + + class BlacklistItemTable(Table): ipv4 = LinkColumn('network.blacklist', args=[A('pk')]) @@ -55,9 +71,7 @@ class GroupTable(Table): class HostTable(Table): hostname = LinkColumn('network.host', args=[A('pk')]) - mac = TemplateColumn( - template_name="network/columns/mac.html" - ) + mac = MACColumn() class Meta: model = Host diff --git a/circle/network/templates/network/columns/mac.html b/circle/network/templates/network/columns/mac.html deleted file mode 100644 index 2c22d37..0000000 --- a/circle/network/templates/network/columns/mac.html +++ /dev/null @@ -1,3 +0,0 @@ -{% load i18n %} - -<span title="{% blocktrans with vendor=record.hw_vendor|default:"n/a" %}Vendor: {{vendor}}{% endblocktrans %}">{{ record.mac }}</span>