Merge branch 'develop' into feature

This commit is contained in:
jeremystretch 2023-03-20 08:54:22 -04:00
commit 3b9fda0169
13 changed files with 82 additions and 11 deletions

View File

@ -79,7 +79,22 @@ A human-friendly description of what your script does.
### `field_order`
By default, script variables will be ordered in the form as they are defined in the script. `field_order` may be defined as an iterable of field names to determine the order in which variables are rendered. Any fields not included in this iterable be listed last.
By default, script variables will be ordered in the form as they are defined in the script. `field_order` may be defined as an iterable of field names to determine the order in which variables are rendered within a default "Script Data" group. Any fields not included in this iterable be listed last. If `fieldsets` is defined, `field_order` will be ignored. A fieldset group for "Script Execution Parameters" will be added to the end of the form by default for the user.
### `fieldsets`
`fieldsets` may be defined as an iterable of field groups and their field names to determine the order in which variables are group and rendered. Any fields not included in this iterable will not be displayed in the form. If `fieldsets` is defined, `field_order` will be ignored. A fieldset group for "Script Execution Parameters" will be added to the end of the fieldsets by default for the user.
An example fieldset definition is provided below:
```python
class MyScript(Script):
class Meta:
fieldsets = (
('First group', ('field1', 'field2', 'field3')),
('Second group', ('field4', 'field5')),
)
```
### `commit_default`

View File

@ -1,5 +1,18 @@
# NetBox v3.4
## v3.4.7 (FUTURE)
### Enhancements
* [#11833](https://github.com/netbox-community/netbox/issues/11833) - Add fieldset support for custom script forms
### Bug Fixes
* [#11984](https://github.com/netbox-community/netbox/issues/11984) - Remove erroneous 802.3az PoE type
* [#11979](https://github.com/netbox-community/netbox/issues/11979) - Correct URL for tags in route targets list
---
## v3.4.6 (2023-03-13)
### Enhancements

View File

@ -1137,7 +1137,6 @@ class InterfacePoETypeChoices(ChoiceSet):
TYPE_1_8023AF = 'type1-ieee802.3af'
TYPE_2_8023AT = 'type2-ieee802.3at'
TYPE_2_8023AZ = 'type2-ieee802.3az'
TYPE_3_8023BT = 'type3-ieee802.3bt'
TYPE_4_8023BT = 'type4-ieee802.3bt'
@ -1152,7 +1151,6 @@ class InterfacePoETypeChoices(ChoiceSet):
(
(TYPE_1_8023AF, '802.3af (Type 1)'),
(TYPE_2_8023AT, '802.3at (Type 2)'),
(TYPE_2_8023AZ, '802.3az (Type 2)'),
(TYPE_3_8023BT, '802.3bt (Type 3)'),
(TYPE_4_8023BT, '802.3bt (Type 4)'),
)

View File

@ -352,6 +352,18 @@ class BaseScript:
# Set initial "commit" checkbox state based on the script's Meta parameter
form.fields['_commit'].initial = getattr(self.Meta, 'commit_default', True)
# Append the default fieldset if defined in the Meta class
default_fieldset = (
('Script Execution Parameters', ('_schedule_at', '_interval', '_commit')),
)
if not hasattr(self.Meta, 'fieldsets'):
fields = (
name for name, _ in self._get_vars().items()
)
self.Meta.fieldsets = (('Script Data', fields),)
self.Meta.fieldsets += default_fieldset
return form
# Logging

View File

@ -1,3 +1,5 @@
import json
import django_tables2 as tables
from django.conf import settings
from django.utils.translation import gettext as _
@ -122,11 +124,14 @@ class SavedFilterTable(NetBoxTable):
enabled = columns.BooleanColumn()
shared = columns.BooleanColumn()
def value_parameters(self, value):
return json.dumps(value)
class Meta(NetBoxTable.Meta):
model = SavedFilter
fields = (
'pk', 'id', 'name', 'slug', 'content_types', 'description', 'user', 'weight', 'enabled', 'shared',
'created', 'last_updated',
'created', 'last_updated', 'parameters'
)
default_columns = (
'pk', 'name', 'content_types', 'user', 'description', 'enabled', 'shared',

View File

@ -62,7 +62,7 @@ class RouteTargetTable(TenancyColumnsMixin, NetBoxTable):
)
comments = columns.MarkdownColumn()
tags = columns.TagColumn(
url_name='ipam:vrf_list'
url_name='ipam:routetarget_list'
)
class Meta(NetBoxTable.Meta):

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -42,3 +42,9 @@ input[type='search']::-webkit-search-results-button,
input[type='search']::-webkit-search-results-decoration {
-webkit-appearance: none !important;
}
// Remove x-axis padding from highlighted text
mark {
padding-left: 0;
padding-right: 0;
}

View File

@ -47,16 +47,34 @@
{% csrf_token %}
<div class="field-group my-4">
{% if form.requires_input %}
{% if script.Meta.fieldsets %}
{# Render grouped fields according to declared fieldsets #}
{% for group, fields in script.Meta.fieldsets %}
<div class="field-group mb-5">
<div class="row mb-2">
<h5 class="offset-sm-3">{{ group }}</h5>
</div>
{% for name in fields %}
{% with field=form|getfield:name %}
{% render_field field %}
{% endwith %}
{% endfor %}
</div>
{% endfor %}
{% else %}
{# Render all fields as a single group #}
<div class="row mb-2">
<h5 class="offset-sm-3">Script Data</h5>
</div>
{% render_form form %}
{% endif %}
{% else %}
<div class="alert alert-info">
<i class="mdi mdi-information"></i>
This script does not require any input to run.
</div>
{% endif %}
{% render_form form %}
{% endif %}
</div>
<div class="float-end">
<a href="{% url 'extras:script_list' %}" class="btn btn-outline-danger">Cancel</a>

View File

@ -214,8 +214,12 @@ def parse_csv(reader):
header = header.strip()
if '.' in header:
field, to_field = header.split('.', 1)
if field in headers:
raise forms.ValidationError(f'Duplicate or conflicting column header for "{field}"')
headers[field] = to_field
else:
if header in headers:
raise forms.ValidationError(f'Duplicate or conflicting column header for "{header}"')
headers[header] = None
# Parse CSV rows into a list of dictionaries mapped from the column headers.

View File

@ -190,7 +190,7 @@ class WirelessLink(WirelessAuthenticationBase, PrimaryModel):
)
def __str__(self):
return f'#{self.pk}'
return self.ssid or f'#{self.pk}'
def get_absolute_url(self):
return reverse('wireless:wirelesslink', args=[self.pk])