mirror of
https://github.com/eduardogsilva/wireguard_webadmin.git
synced 2026-01-17 13:06:18 +00:00
add display_name property to Worker model for customizable display options
This commit is contained in:
@@ -54,6 +54,42 @@ class Worker(models.Model):
|
|||||||
created = models.DateTimeField(auto_now_add=True)
|
created = models.DateTimeField(auto_now_add=True)
|
||||||
uuid = models.UUIDField(default=uuid.uuid4, editable=False, unique=True)
|
uuid = models.UUIDField(default=uuid.uuid4, editable=False, unique=True)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.name
|
||||||
|
|
||||||
|
@property
|
||||||
|
def display_name(self):
|
||||||
|
cluster_settings = ClusterSettings.objects.first()
|
||||||
|
if not cluster_settings:
|
||||||
|
return self.name
|
||||||
|
|
||||||
|
mode = cluster_settings.worker_display
|
||||||
|
|
||||||
|
hostname = self.hostname or ''
|
||||||
|
ip_address = self.ip_address or ''
|
||||||
|
city = self.city or ''
|
||||||
|
country = self.country or ''
|
||||||
|
|
||||||
|
location_parts = [part for part in (city, country) if part]
|
||||||
|
location = ', '.join(location_parts)
|
||||||
|
|
||||||
|
if mode == 'name':
|
||||||
|
return self.name
|
||||||
|
|
||||||
|
if mode == 'server_address':
|
||||||
|
return hostname or ip_address or self.name
|
||||||
|
|
||||||
|
if mode == 'location':
|
||||||
|
return location or self.name
|
||||||
|
|
||||||
|
if mode == 'address_location':
|
||||||
|
address = hostname or ip_address
|
||||||
|
if address and location:
|
||||||
|
return f"{address} ({location})"
|
||||||
|
return address or location or self.name
|
||||||
|
|
||||||
|
return self.name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_online(self):
|
def is_online(self):
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
{% for worker in workers %}
|
{% for worker in workers %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ worker.name }}</td>
|
<td>{{ worker }}</td>
|
||||||
<td style="width: 1%; white-space: nowrap;">
|
<td style="width: 1%; white-space: nowrap;">
|
||||||
{% if worker.error_status %}
|
{% if worker.error_status %}
|
||||||
<i class="fas fa-exclamation-triangle text-danger blink" title="{{ worker.get_error_status_display }}"></i>
|
<i class="fas fa-exclamation-triangle text-danger blink" title="{{ worker.get_error_status_display }}"></i>
|
||||||
|
|||||||
Reference in New Issue
Block a user