mirror of
https://github.com/netbox-community/netbox.git
synced 2026-01-23 12:08:43 -06:00
Compare commits
2 Commits
19129-mac-
...
21254-attr
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a320df9926 | ||
|
|
3dcca73ecc |
@@ -732,25 +732,6 @@ class BaseInterface(models.Model):
|
||||
if self.primary_mac_address:
|
||||
return self.primary_mac_address.mac_address
|
||||
|
||||
@property
|
||||
def mac_address_display(self):
|
||||
"""
|
||||
Rich representation of MAC addresses for use in table columns (e.g. InterfaceTable).
|
||||
Handles various configurations of MAC addresses for an interface:
|
||||
11:22:33:44:55:66 <-- Single MAC address on interface, assigned as primary
|
||||
11:22:33:44:55:66 (2) <-- Multiple MAC addresses on interface, one assigned as primary
|
||||
2 available <-- 1 or more MAC addresses on interface, none assigned as primary
|
||||
- <-- No MAC addresses on interface
|
||||
"""
|
||||
available_mac_count = self.mac_addresses.count()
|
||||
if self.primary_mac_address:
|
||||
if available_mac_count > 1:
|
||||
return f"{self.primary_mac_address} ({available_mac_count})"
|
||||
return self.primary_mac_address
|
||||
if available_mac_count:
|
||||
return f"{available_mac_count} available"
|
||||
return None
|
||||
|
||||
|
||||
class Interface(
|
||||
InterfaceValidationMixin,
|
||||
|
||||
@@ -616,7 +616,6 @@ class BaseInterfaceTable(NetBoxTable):
|
||||
)
|
||||
primary_mac_address = tables.Column(
|
||||
verbose_name=_('MAC Address'),
|
||||
accessor=Accessor('mac_address_display'),
|
||||
linkify=True
|
||||
)
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ def enqueue_event(queue, instance, request, event_type):
|
||||
|
||||
|
||||
def process_event_rules(event_rules, object_type, event_type, data, username=None, snapshots=None, request=None):
|
||||
user = User.objects.get(username=username) if username else None
|
||||
user = None # To be resolved from the username if needed
|
||||
|
||||
for event_rule in event_rules:
|
||||
|
||||
@@ -134,6 +134,10 @@ def process_event_rules(event_rules, object_type, event_type, data, username=Non
|
||||
# Resolve the script from action parameters
|
||||
script = event_rule.action_object.python_class()
|
||||
|
||||
# Retrieve the User if not already resolved
|
||||
if user is None:
|
||||
user = User.objects.get(username=username)
|
||||
|
||||
# Enqueue a Job to record the script's execution
|
||||
from extras.jobs import ScriptJob
|
||||
params = {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import re
|
||||
from collections import namedtuple
|
||||
import logging
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib import messages
|
||||
@@ -28,6 +29,8 @@ __all__ = (
|
||||
'SearchView',
|
||||
)
|
||||
|
||||
logger = logging.getLogger(f'netbox.{__name__}')
|
||||
|
||||
Link = namedtuple('Link', ('label', 'viewname', 'permission', 'count'))
|
||||
|
||||
|
||||
@@ -50,7 +53,14 @@ class HomeView(ConditionalLoginRequiredMixin, View):
|
||||
# Check whether a new release is available. (Only for superusers.)
|
||||
new_release = None
|
||||
if request.user.is_superuser:
|
||||
latest_release = cache.get('latest_release')
|
||||
# cache.get() can raise if the cached value can't be unpickled after dependency upgrades
|
||||
try:
|
||||
latest_release = cache.get('latest_release')
|
||||
except Exception:
|
||||
logger.debug("Failed to read 'latest_release' from cache; deleting key", exc_info=True)
|
||||
cache.delete('latest_release')
|
||||
latest_release = None
|
||||
|
||||
if latest_release:
|
||||
release_version, release_url = latest_release
|
||||
if release_version > version.parse(settings.RELEASE.version):
|
||||
|
||||
@@ -143,11 +143,9 @@
|
||||
<tr>
|
||||
<th scope="row">{% trans "MAC Address" %}</th>
|
||||
<td>
|
||||
{% if object.mac_address_display %}
|
||||
<span class="font-monospace">{{ object.mac_address_display|linkify }}</span>
|
||||
{% if object.primary_mac_address %}
|
||||
<span class="badge text-bg-primary">{% trans "Primary" %}</span>
|
||||
{% endif %}
|
||||
{% if object.primary_mac_address %}
|
||||
<span class="font-monospace">{{ object.primary_mac_address|linkify }}</span>
|
||||
<span class="badge text-bg-primary">{% trans "Primary" %}</span>
|
||||
{% else %}
|
||||
{{ ''|placeholder }}
|
||||
{% endif %}
|
||||
|
||||
@@ -78,11 +78,9 @@
|
||||
<tr>
|
||||
<th scope="row">{% trans "MAC Address" %}</th>
|
||||
<td>
|
||||
{% if object.mac_address_display %}
|
||||
<span class="font-monospace">{{ object.mac_address_display|linkify }}</span>
|
||||
{% if object.primary_mac_address %}
|
||||
<span class="badge text-bg-primary">{% trans "Primary" %}</span>
|
||||
{% endif %}
|
||||
{% if object.mac_address %}
|
||||
<span class="font-monospace">{{ object.mac_address }}</span>
|
||||
<span class="badge text-bg-primary">{% trans "Primary" %}</span>
|
||||
{% else %}
|
||||
{{ ''|placeholder }}
|
||||
{% endif %}
|
||||
|
||||
Reference in New Issue
Block a user