Просмотр исходного кода

Merge pull request #8329 from jasonyates/8293-asdot

Adding asdot notation to ASN views
Jeremy Stretch 4 лет назад
Родитель
Сommit
aa77f8f0d2
3 измененных файлов с 14 добавлено и 2 удалено
  1. 9 1
      netbox/ipam/models/ip.py
  2. 4 0
      netbox/ipam/tables/ip.py
  3. 1 1
      netbox/templates/ipam/asn.html

+ 9 - 1
netbox/ipam/models/ip.py

@@ -125,11 +125,19 @@ class ASN(PrimaryModel):
         verbose_name_plural = 'ASNs'
 
     def __str__(self):
-        return f'AS{self.asn}'
+        return f'AS{self.asn_with_asdot}'
 
     def get_absolute_url(self):
         return reverse('ipam:asn', args=[self.pk])
 
+    @property
+    def asn_with_asdot(self):
+        # Return asn with asdot notation for an ASN larger than 65535 otherwise return the plain ASN
+        if self.asn > 65535:
+            return f'{self.asn} ({self.asn // 65536}.{self.asn % 65536})'
+        else:
+            return self.asn
+
 
 @extras_features('custom_fields', 'custom_links', 'export_templates', 'tags', 'webhooks')
 class Aggregate(GetAvailablePrefixesMixin, PrimaryModel):

+ 4 - 0
netbox/ipam/tables/ip.py

@@ -106,6 +106,10 @@ class ASNTable(BaseTable):
     asn = tables.Column(
         linkify=True
     )
+
+    def render_asn(self, value, record):
+        return record.asn_with_asdot
+
     site_count = LinkedCountColumn(
         viewname='dcim:site_list',
         url_params={'asn_id': 'pk'},

+ 1 - 1
netbox/templates/ipam/asn.html

@@ -18,7 +18,7 @@
           <table class="table table-hover attr-table">
             <tr>
               <td>AS Number</td>
-              <td>{{ object.asn }}</td>
+              <td>{{ object.asn_with_asdot }}</td>
             </tr>
             <tr>
               <td>RIR</td>