Skip to content

Commit

Permalink
Cleanup & docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremystretch committed Mar 14, 2023
1 parent f715064 commit 5cd3ad0
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 13 deletions.
4 changes: 4 additions & 0 deletions docs/models/extras/customfield.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ The default value to populate for the custom field when creating new objects (op

For choice and multi-choice custom fields only. A comma-delimited list of the available choices.

### Cloneable

If enabled, values from this field will be automatically pre-populated when cloning existing objects.

### Minimum Value

For numeric custom fields only. The minimum valid value (optional).
Expand Down
1 change: 1 addition & 0 deletions docs/release-notes/version-3.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ A new ASN range model has been introduced to facilitate the provisioning of new

* [#7947](https://github.com/netbox-community/netbox/issues/7947) - Enable marking IP ranges as fully utilized
* [#8272](https://github.com/netbox-community/netbox/issues/8272) - Support bridge relationships among device type interfaces
* [#8749](https://github.com/netbox-community/netbox/issues/8749) - Support replicating custom field values when cloning an object
* [#8958](https://github.com/netbox-community/netbox/issues/8958) - Changes in background job status can trigger webhooks
* [#9073](https://github.com/netbox-community/netbox/issues/9073) - Enable syncing config context data from remote sources
* [#9653](https://github.com/netbox-community/netbox/issues/9653) - Enable setting a default platform for device types
Expand Down
5 changes: 3 additions & 2 deletions netbox/extras/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,9 @@ class Meta:
model = CustomField
fields = [
'id', 'url', 'display', 'content_types', 'type', 'object_type', 'data_type', 'name', 'label', 'group_name',
'description', 'required', 'search_weight', 'filter_logic', 'ui_visibility', 'is_cloneable', 'default', 'weight',
'validation_minimum', 'validation_maximum', 'validation_regex', 'choices', 'created', 'last_updated',
'description', 'required', 'search_weight', 'filter_logic', 'ui_visibility', 'is_cloneable', 'default',
'weight', 'validation_minimum', 'validation_maximum', 'validation_regex', 'choices', 'created',
'last_updated',
]

def get_data_type(self, obj):
Expand Down
2 changes: 1 addition & 1 deletion netbox/extras/filtersets.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class Meta:
model = CustomField
fields = [
'id', 'content_types', 'name', 'group_name', 'required', 'search_weight', 'filter_logic', 'ui_visibility',
'weight', 'description',
'weight', 'is_cloneable', 'description',
]

def search(self, queryset, name, value):
Expand Down
10 changes: 9 additions & 1 deletion netbox/extras/forms/filtersets.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
class CustomFieldFilterForm(SavedFiltersMixin, FilterForm):
fieldsets = (
(None, ('q', 'filter_id')),
('Attributes', ('type', 'content_type_id', 'group_name', 'weight', 'required', 'ui_visibility')),
('Attributes', (
'type', 'content_type_id', 'group_name', 'weight', 'required', 'ui_visibility', 'is_cloneable',
)),
)
content_type_id = ContentTypeMultipleChoiceField(
queryset=ContentType.objects.filter(FeatureQuery('custom_fields').get_query()),
Expand Down Expand Up @@ -66,6 +68,12 @@ class CustomFieldFilterForm(SavedFiltersMixin, FilterForm):
required=False,
label=_('UI visibility')
)
is_cloneable = forms.NullBooleanField(
required=False,
widget=forms.Select(
choices=BOOLEAN_WITH_BLANK_CHOICES
)
)


class JobResultFilterForm(SavedFiltersMixin, FilterForm):
Expand Down
2 changes: 1 addition & 1 deletion netbox/extras/forms/model_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class CustomFieldForm(BootstrapMixin, forms.ModelForm):
('Custom Field', (
'content_types', 'name', 'label', 'group_name', 'type', 'object_type', 'required', 'description',
)),
('Behavior', ('search_weight', 'filter_logic', 'ui_visibility', 'is_cloneable', 'weight')),
('Behavior', ('search_weight', 'filter_logic', 'ui_visibility', 'weight', 'is_cloneable')),
('Values', ('default', 'choices')),
('Validation', ('validation_minimum', 'validation_maximum', 'validation_regex')),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class Migration(migrations.Migration):

dependencies = [
('extras', '0084_staging'),
('extras', '0088_jobresult_webhooks'),
]

operations = [
Expand Down
4 changes: 3 additions & 1 deletion netbox/extras/tables/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ class CustomFieldTable(NetBoxTable):
content_types = columns.ContentTypesColumn()
required = columns.BooleanColumn()
ui_visibility = columns.ChoiceFieldColumn(verbose_name="UI visibility")
is_cloneable = columns.BooleanColumn()

class Meta(NetBoxTable.Meta):
model = CustomField
fields = (
'pk', 'id', 'name', 'content_types', 'label', 'type', 'group_name', 'required', 'default', 'description',
'search_weight', 'filter_logic', 'ui_visibility', 'is_cloneable', 'weight', 'choices', 'created', 'last_updated',
'search_weight', 'filter_logic', 'ui_visibility', 'is_cloneable', 'weight', 'choices', 'created',
'last_updated',
)
default_columns = ('pk', 'name', 'content_types', 'label', 'group_name', 'type', 'required', 'description')

Expand Down
9 changes: 3 additions & 6 deletions netbox/netbox/models/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,11 @@ def clone(self):
if is_taggable(self):
attrs['tags'] = [tag.pk for tag in self.tags.all()]

# check custom fields
# Include any cloneable custom fields
if hasattr(self, 'custom_field_data'):
from extras.models import CustomField

for field in CustomField.objects.get_for_model(self):
for field in self.get_custom_fields():
if field.is_cloneable:
value = self.custom_field_data.get(field.name)
attrs[f'cf_{field.name}'] = field.deserialize(value)
attrs[f'cf_{field.name}'] = self.custom_field_data.get(field.name)

return attrs

Expand Down

0 comments on commit 5cd3ad0

Please sign in to comment.