mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-21 11:37:21 -06:00
Extend linkify() to accept an attr name for the link text
This commit is contained in:
parent
75dae5fbe8
commit
8d682041a4
@ -79,9 +79,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">Name</th>
|
<th scope="row">Name</th>
|
||||||
<td>
|
<td>{{ object.connected_endpoint|linkify:"name" }}</td>
|
||||||
<a href="{{ object.connected_endpoint.get_absolute_url }}">{{ object.connected_endpoint.name }}</a>
|
|
||||||
</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">Type</th>
|
<th scope="row">Type</th>
|
||||||
|
@ -81,9 +81,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">Name</th>
|
<th scope="row">Name</th>
|
||||||
<td>
|
<td>{{ object.connected_endpoint|linkify:"name" }}</td>
|
||||||
<a href="{{ object.connected_endpoint.get_absolute_url }}">{{ object.connected_endpoint.name }}</a>
|
|
||||||
</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">Type</th>
|
<th scope="row">Type</th>
|
||||||
|
@ -8,9 +8,7 @@
|
|||||||
{% with tagged_vlans=obj.tagged_vlans.all %}
|
{% with tagged_vlans=obj.tagged_vlans.all %}
|
||||||
{% if obj.untagged_vlan and obj.untagged_vlan not in tagged_vlans %}
|
{% if obj.untagged_vlan and obj.untagged_vlan not in tagged_vlans %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>{{ obj.untagged_vlan|linkify:"vid" }}</td>
|
||||||
<a href="{{ obj.untagged_vlan.get_absolute_url }}">{{ obj.untagged_vlan.vid }}</a>
|
|
||||||
</td>
|
|
||||||
<td>{{ obj.untagged_vlan.name }}</td>
|
<td>{{ obj.untagged_vlan.name }}</td>
|
||||||
<td>
|
<td>
|
||||||
<input type="radio" name="untagged_vlan" value="{{ obj.untagged_vlan.pk }}" checked="checked" />
|
<input type="radio" name="untagged_vlan" value="{{ obj.untagged_vlan.pk }}" checked="checked" />
|
||||||
@ -22,9 +20,7 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{% for vlan in tagged_vlans %}
|
{% for vlan in tagged_vlans %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>{{ vlan|linkify:"vid" }}</td>
|
||||||
<a href="{{ vlan.get_absolute_url }}">{{ vlan.vid }}</a>
|
|
||||||
</td>
|
|
||||||
<td>{{ vlan.name }}</td>
|
<td>{{ vlan.name }}</td>
|
||||||
<td>
|
<td>
|
||||||
<input type="radio" name="untagged_vlan" value="{{ vlan.pk }}"{% if vlan == obj.untagged_vlan %} checked="checked"{% endif %} />
|
<input type="radio" name="untagged_vlan" value="{{ vlan.pk }}"{% if vlan == obj.untagged_vlan %} checked="checked"{% endif %} />
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
{% for item in object.inventory_items.all %}
|
{% for item in object.inventory_items.all %}
|
||||||
<tr>
|
<tr>
|
||||||
<td><a href="{{ item.get_absolute_url }}">{{ item.name }}</a></td>
|
<td>{{ item|linkify:"name" }}</td>
|
||||||
<td>{{ item.label|placeholder }}</td>
|
<td>{{ item.label|placeholder }}</td>
|
||||||
<td>{{ item.role|linkify|placeholder }}</td>
|
<td>{{ item.role|linkify|placeholder }}</td>
|
||||||
<td class="text-end noprint">
|
<td class="text-end noprint">
|
||||||
|
@ -152,9 +152,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">Name</th>
|
<th scope="row">Name</th>
|
||||||
<td>
|
<td>{{ iface|linkify:"name" }}</td>
|
||||||
<a href="{{ iface.get_absolute_url }}">{{ iface.name }}</a>
|
|
||||||
</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">Type</th>
|
<th scope="row">Type</th>
|
||||||
@ -370,9 +368,7 @@
|
|||||||
—
|
—
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>{{ wlan|linkify:"ssid" }}</td>
|
||||||
<a href="{{ wlan.get_absolute_url }}">{{ wlan.ssid }}</a>
|
|
||||||
</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
{% empty %}
|
{% empty %}
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -127,9 +127,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">Name</th>
|
<th scope="row">Name</th>
|
||||||
<td>
|
<td>{{ object.connected_endpoint|linkify:"name" }}</td>
|
||||||
<a href="{{ object.connected_endpoint.get_absolute_url }}">{{ object.connected_endpoint.name }}</a>
|
|
||||||
</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">Type</th>
|
<th scope="row">Type</th>
|
||||||
|
@ -85,9 +85,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">Name</th>
|
<th scope="row">Name</th>
|
||||||
<td>
|
<td>{{ object.connected_endpoint|linkify:"name" }}</td>
|
||||||
<a href="{{ object.connected_endpoint.get_absolute_url }}">{{ object.connected_endpoint.name }}</a>
|
|
||||||
</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">Type</th>
|
<th scope="row">Type</th>
|
||||||
|
@ -85,9 +85,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">Name</th>
|
<th scope="row">Name</th>
|
||||||
<td>
|
<td>{{ object.connected_endpoint|linkify:"name" }}</td>
|
||||||
<a href="{{ object.connected_endpoint.get_absolute_url }}">{{ object.connected_endpoint.name }}</a>
|
|
||||||
</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">Type</th>
|
<th scope="row">Type</th>
|
||||||
|
@ -206,9 +206,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
{% for resv in reservations %}
|
{% for resv in reservations %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>{{ resv|linkify:"unit_list" }}</td>
|
||||||
<a href="{{ resv.get_absolute_url }}">{{ resv.unit_list }}</a>
|
|
||||||
</td>
|
|
||||||
<td>{{ resv.tenant|linkify|placeholder }}</td>
|
<td>{{ resv.tenant|linkify|placeholder }}</td>
|
||||||
<td>
|
<td>
|
||||||
{{ resv.description }}<br />
|
{{ resv.description }}<br />
|
||||||
|
@ -43,7 +43,7 @@
|
|||||||
<div class="float-end">
|
<div class="float-end">
|
||||||
<span class="text-muted">{{ context.weight }}</span>
|
<span class="text-muted">{{ context.weight }}</span>
|
||||||
</div>
|
</div>
|
||||||
<a href="{{ context.get_absolute_url }}"><strong>{{ context.name }}</strong></a>
|
<strong>{{ context|linkify:"name" }}"></strong>
|
||||||
{% if context.description %}
|
{% if context.description %}
|
||||||
<br /><small>{{ context.description }}</small>
|
<br /><small>{{ context.description }}</small>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -61,7 +61,7 @@
|
|||||||
<th scope="row">Object</th>
|
<th scope="row">Object</th>
|
||||||
<td>
|
<td>
|
||||||
{% if object.changed_object and object.changed_object.get_absolute_url %}
|
{% if object.changed_object and object.changed_object.get_absolute_url %}
|
||||||
<a href="{{ object.changed_object.get_absolute_url }}">{{ object.changed_object }}</a>
|
{{ object.changed_object|linkify }}
|
||||||
{% else %}
|
{% else %}
|
||||||
{{ object.object_repr }}
|
{{ object.object_repr }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -16,21 +16,14 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
{% for assignment in object.fhrp_group_assignments.all %}
|
{% for assignment in object.fhrp_group_assignments.all %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>{{ assignment.group|linkify:"group_id" }}</td>
|
||||||
<a href="{{ assignment.group.get_absolute_url }}">{{ assignment.group.group_id }}</a>
|
<td>{{ assignment.group.get_protocol_display }}</td>
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
{{ assignment.group.get_protocol_display }}
|
|
||||||
</td>
|
|
||||||
<td>
|
<td>
|
||||||
{% for ipaddress in assignment.group.ip_addresses.all %}
|
{% for ipaddress in assignment.group.ip_addresses.all %}
|
||||||
{{ ipaddress|linkify }}
|
{{ ipaddress|linkify }}{% if not forloop.last %}<br />{% endif %}
|
||||||
{% if not forloop.last %}<br />{% endif %}
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>{{ assignment.priority }}</td>
|
||||||
{{ assignment.priority }}
|
|
||||||
</td>
|
|
||||||
<td class="text-end noprint">
|
<td class="text-end noprint">
|
||||||
{% if perms.ipam.change_fhrpgroupassignment %}
|
{% if perms.ipam.change_fhrpgroupassignment %}
|
||||||
<a href="{% url 'ipam:fhrpgroupassignment_edit' pk=assignment.pk %}?return_url={{ object.get_absolute_url }}" class="btn btn-warning btn-sm lh-1" title="Edit">
|
<a href="{% url 'ipam:fhrpgroupassignment_edit' pk=assignment.pk %}?return_url={{ object.get_absolute_url }}" class="btn btn-warning btn-sm lh-1" title="Edit">
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td><a href="{{ service.get_absolute_url }}">{{ service.name }}</a></td>
|
<td>{{ service|linkify:"name" }}</td>
|
||||||
<td>{{ service.get_protocol_display }}</td>
|
<td>{{ service.get_protocol_display }}</td>
|
||||||
<td>{{ service.port_list }}</td>
|
<td>{{ service.port_list }}</td>
|
||||||
<td>
|
<td>
|
||||||
|
@ -21,16 +21,24 @@ register = template.Library()
|
|||||||
#
|
#
|
||||||
|
|
||||||
@register.filter()
|
@register.filter()
|
||||||
def linkify(instance):
|
def linkify(instance, attr=None):
|
||||||
"""
|
"""
|
||||||
Render a hyperlink for object's with a `get_absolute_url()` method, using the object's string representation
|
Render a hyperlink for an object with a `get_absolute_url()` method, optionally specifying the name of an
|
||||||
as the link's text. If the object has no `get_absolute_url()` method, return an empty string.
|
attribute to use for the link text. If no attribute is given, the object's string representation will be
|
||||||
|
used.
|
||||||
|
|
||||||
|
If the object has no `get_absolute_url()` method, return the text without a hyperlink element.
|
||||||
"""
|
"""
|
||||||
try:
|
if instance is None:
|
||||||
return mark_safe(f'<a href="{instance.get_absolute_url()}">{instance}</a>')
|
|
||||||
except (AttributeError, TypeError):
|
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
text = getattr(instance, attr) if attr is not None else str(instance)
|
||||||
|
try:
|
||||||
|
url = instance.get_absolute_url()
|
||||||
|
return mark_safe(f'<a href="{url}">{text}</a>')
|
||||||
|
except (AttributeError, TypeError):
|
||||||
|
return text
|
||||||
|
|
||||||
|
|
||||||
@register.filter()
|
@register.filter()
|
||||||
def bettertitle(value):
|
def bettertitle(value):
|
||||||
|
Loading…
Reference in New Issue
Block a user