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

Suggested changes

* Updating asdot computation to use an fstring
* Cleaning code. Custom property now returns either the ASN with ASDOT notation or just the ASN. asn_with_asdot can now be referenced in ASNTable & objet template.
Jason Yates 4 лет назад
Родитель
Сommit
62fc7717c8
3 измененных файлов с 7 добавлено и 13 удалено
  1. 5 8
      netbox/ipam/models/ip.py
  2. 1 4
      netbox/ipam/tables/ip.py
  3. 1 1
      netbox/templates/ipam/asn.html

+ 5 - 8
netbox/ipam/models/ip.py

@@ -125,21 +125,18 @@ class ASN(PrimaryModel):
         verbose_name_plural = 'ASNs'
 
     def __str__(self):
-        if self.asn > 65535:
-            return 'AS{} ({}.{})'.format(self.asn, self.asn // 65536, self.asn % 65536)
-        else:
-            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 asdot_notation(self):
-        # Return asdot notation for an ASN larger than 65535
+    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 '{}.{}'.format(self.asn // 65536, self.asn % 65536)
+            return f'{self.asn} ({self.asn // 65536}.{self.asn % 65536})'
         else:
-            return None
+            return self.asn
 
 
 @extras_features('custom_fields', 'custom_links', 'export_templates', 'tags', 'webhooks')

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

@@ -108,10 +108,7 @@ class ASNTable(BaseTable):
     )
 
     def render_asn(self, value, record):
-        if record.asdot_notation:
-            return f'{value} ({record.asdot_notation})'
-        else:
-            return value
+        return record.asn_with_asdot
 
     site_count = LinkedCountColumn(
         viewname='dcim:site_list',

+ 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 }} {% if object.asdot_notation %}({{ object.asdot_notation }}){% endif %}</td>
+              <td>{{ object.asn_with_asdot }}</td>
             </tr>
             <tr>
               <td>RIR</td>