mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-17 13:08:16 -06:00
Add 'Any' display to admin form
This commit is contained in:
parent
fa15c879ff
commit
de417a0296
@ -45,7 +45,7 @@
|
||||
<div class="col col-md-3">
|
||||
<small class="text-muted">Allowed Source IPs</small><br />
|
||||
{% if token.allowed_ips %}
|
||||
{{ token.allowed_ips }}
|
||||
{{ token.allowed_ips|join:', ' }}
|
||||
{% else %}
|
||||
<span>Any</span>
|
||||
{% endif %}
|
||||
|
@ -59,9 +59,14 @@ class UserAdmin(UserAdmin_):
|
||||
class TokenAdmin(admin.ModelAdmin, DynamicArrayMixin):
|
||||
form = forms.TokenAdminForm
|
||||
list_display = [
|
||||
'key', 'user', 'created', 'expires', 'write_enabled', 'description', 'allowed_ips'
|
||||
'key', 'user', 'created', 'expires', 'write_enabled', 'description', 'list_allowed_ips'
|
||||
]
|
||||
|
||||
def list_allowed_ips(self, obj):
|
||||
return obj.allowed_ips
|
||||
list_allowed_ips.empty_value_display = 'Any'
|
||||
list_allowed_ips.short_description = "Allowed IPs"
|
||||
|
||||
|
||||
#
|
||||
# Permissions
|
||||
|
@ -1,8 +1,10 @@
|
||||
from django import forms
|
||||
from django.contrib.auth.forms import AuthenticationForm, PasswordChangeForm as DjangoPasswordChangeForm
|
||||
from django.contrib.postgres.forms import SimpleArrayField
|
||||
|
||||
from utilities.forms import BootstrapMixin, DateTimePicker
|
||||
from .models import Token
|
||||
from ipam.formfields import IPNetworkFormField
|
||||
|
||||
|
||||
class LoginForm(BootstrapMixin, AuthenticationForm):
|
||||
@ -18,6 +20,11 @@ class TokenForm(BootstrapMixin, forms.ModelForm):
|
||||
required=False,
|
||||
help_text="If no key is provided, one will be generated automatically."
|
||||
)
|
||||
allowed_ips = SimpleArrayField(
|
||||
base_field=IPNetworkFormField(),
|
||||
required=False,
|
||||
help_text='Allowed IPv4/IPv6 networks from where the token can be used. Leave blank for no restrictions. Ex: "10.1.1.0/24, 192.168.10.16/32, 2001:DB8:1::/64"',
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = Token
|
||||
|
Loading…
Reference in New Issue
Block a user