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

Closes #7925: Linkify contact phone and email attributes

jeremystretch 4 лет назад
Родитель
Сommit
68f322a03b

+ 1 - 1
docs/release-notes/version-3.1.md

@@ -15,7 +15,7 @@
 * [#7812](https://github.com/netbox-community/netbox/issues/7812) - Enable change logging for image attachments
 * [#7858](https://github.com/netbox-community/netbox/issues/7858) - Standardize the representation of content types across import & export functions
 * [#7884](https://github.com/netbox-community/netbox/issues/7884) - Add FHRP groups column to interface tables
-* [#7940](https://github.com/netbox-community/netbox/issues/7940) - Add ITA multistandard outlet
+* [#7925](https://github.com/netbox-community/netbox/issues/7925) - Linkify contact phone and email attributes
 
 ### Bug Fixes
 

+ 14 - 2
netbox/templates/tenancy/contact.html

@@ -37,11 +37,23 @@
             </tr>
             <tr>
               <td>Phone</td>
-              <td>{{ object.phone|placeholder }}</td>
+              <td>
+                {% if object.phone %}
+                  <a href="tel:{{ object.phone }}">{{ object.phone }}</a>
+                {% else %}
+                  <span class="text-muted">None</span>
+                {% endif %}
+              </td>
             </tr>
             <tr>
               <td>Email</td>
-              <td>{{ object.email|placeholder }}</td>
+              <td>
+                {% if object.phone %}
+                  <a href="mailto:{{ object.email }}">{{ object.email }}</a>
+                {% else %}
+                  <span class="text-muted">None</span>
+                {% endif %}
+              </td>
             </tr>
             <tr>
               <td>Address</td>

+ 5 - 1
netbox/tenancy/tables.py

@@ -1,7 +1,8 @@
 import django_tables2 as tables
 
 from utilities.tables import (
-    BaseTable, ButtonsColumn, ContentTypeColumn, LinkedCountColumn, MarkdownColumn, MPTTColumn, TagColumn, ToggleColumn,
+    BaseTable, ButtonsColumn, ContentTypeColumn, LinkedCountColumn, linkify_phone, MarkdownColumn, MPTTColumn,
+    TagColumn, ToggleColumn,
 )
 from .models import *
 
@@ -131,6 +132,9 @@ class ContactTable(BaseTable):
     group = tables.Column(
         linkify=True
     )
+    phone = tables.Column(
+        linkify=linkify_phone,
+    )
     comments = MarkdownColumn()
     assignment_count = tables.Column(
         verbose_name='Assignments'

+ 16 - 0
netbox/utilities/tables.py

@@ -489,3 +489,19 @@ def paginate_table(table, request):
         'per_page': get_paginate_count(request)
     }
     RequestConfig(request, paginate).configure(table)
+
+
+#
+# Callables
+#
+
+def linkify_email(value):
+    if value is None:
+        return None
+    return f"mailto:{value}"
+
+
+def linkify_phone(value):
+    if value is None:
+        return None
+    return f"tel:{value}"