Skip to content

Commit 23c0ca4

Browse files
committed
#4347: Rename NetBoxModelCSVForm to NetBoxModelImportForm
1 parent d9d25ff commit 23c0ca4

File tree

19 files changed

+248
-233
lines changed

19 files changed

+248
-233
lines changed

docs/plugins/development/forms.md

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
NetBox provides several base form classes for use by plugins.
66

7-
| Form Class | Purpose |
8-
|---------------------------|--------------------------------------|
9-
| `NetBoxModelForm` | Create/edit individual objects |
10-
| `NetBoxModelCSVForm` | Bulk import objects from CSV data |
11-
| `NetBoxModelBulkEditForm` | Edit multiple objects simultaneously |
7+
| Form Class | Purpose |
8+
|----------------------------|--------------------------------------|
9+
| `NetBoxModelForm` | Create/edit individual objects |
10+
| `NetBoxModelImportForm` | Bulk import objects from CSV data |
11+
| `NetBoxModelBulkEditForm` | Edit multiple objects simultaneously |
1212
| `NetBoxModelFilterSetForm` | Filter objects within a list view |
1313

1414
### `NetBoxModelForm`
@@ -45,19 +45,20 @@ class MyModelForm(NetBoxModelForm):
4545
!!! tip "Comment fields"
4646
If your form has a `comments` field, there's no need to list it; this will always appear last on the page.
4747

48-
### `NetBoxModelCSVForm`
48+
### `NetBoxModelImportForm`
4949

50-
This form facilitates the bulk import of new objects from CSV data. As with model forms, you'll need to declare a `Meta` subclass specifying the associated `model` and `fields`. NetBox also provides several form fields suitable for import various types of CSV data, listed below.
50+
This form facilitates the bulk import of new objects from CSV, JSON, or YAML data. As with model forms, you'll need to declare a `Meta` subclass specifying the associated `model` and `fields`. NetBox also provides several form fields suitable for import various types of CSV data, listed below.
5151

5252
**Example**
5353

5454
```python
5555
from dcim.models import Site
56-
from netbox.forms import NetBoxModelCSVForm
56+
from netbox.forms import NetBoxModelImportForm
5757
from utilities.forms import CSVModelChoiceField
5858
from .models import MyModel
5959

60-
class MyModelCSVForm(NetBoxModelCSVForm):
60+
61+
class MyModelImportForm(NetBoxModelImportForm):
6162
site = CSVModelChoiceField(
6263
queryset=Site.objects.all(),
6364
to_field_name='name',
@@ -69,6 +70,9 @@ class MyModelCSVForm(NetBoxModelCSVForm):
6970
fields = ('name', 'status', 'site', 'comments')
7071
```
7172

73+
!!! note "Previously NetBoxModelCSVForm"
74+
This form class was previously named `NetBoxModelCSVForm`. It was renamed in NetBox v3.4 to convey support for JSON and YAML formats in addition to CSV. The `NetBoxModelCSVForm` class has been retained for backward compatibility and functions exactly the same as `NetBoxModelImportForm`. However, plugin authors should be aware that this backward compatability will be removed in NetBox v3.5.
75+
7276
### `NetBoxModelBulkEditForm`
7377

7478
This form facilitates editing multiple objects in bulk. Unlike a model form, this form does not have a child `Meta` class, and must explicitly define each field. All fields in a bulk edit form are generally declared with `required=False`.
@@ -84,11 +88,12 @@ This form facilitates editing multiple objects in bulk. Unlike a model form, thi
8488
```python
8589
from django import forms
8690
from dcim.models import Site
87-
from netbox.forms import NetBoxModelCSVForm
91+
from netbox.forms import NetBoxModelImportForm
8892
from utilities.forms import CommentField, DynamicModelChoiceField
8993
from .models import MyModel, MyModelStatusChoices
9094

91-
class MyModelEditForm(NetBoxModelCSVForm):
95+
96+
class MyModelEditForm(NetBoxModelImportForm):
9297
name = forms.CharField(
9398
required=False
9499
)

docs/release-notes/version-3.4.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* The `noc_contact`, `admin_contact`, and `portal_url` fields have been removed from the provider model. Please replicate any data remaining in these fields to the contact model introduced in NetBox v3.1 prior to upgrading.
1111
* The `content_type` field on the CustomLink and ExportTemplate models have been renamed to `content_types` and now supports the assignment of multiple content types.
1212
* The `cf` property on an object with custom fields now returns deserialized values. For example, a custom field referencing an object will return the object instance rather than its numeric ID. To access the raw serialized values, use `custom_field_data` instead.
13+
* The `NetBoxModelCSVForm` class has been renamed to `NetBoxModelImportForm`. Backward compatability with the previous name has been retained for this release, but will be dropped in NetBox v3.5.
1314

1415
### New Features
1516

netbox/circuits/forms/bulk_import.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
from circuits.choices import CircuitStatusChoices
22
from circuits.models import *
33
from django.utils.translation import gettext as _
4-
from netbox.forms import NetBoxModelCSVForm
4+
from netbox.forms import NetBoxModelImportForm
55
from tenancy.models import Tenant
66
from utilities.forms import CSVChoiceField, CSVModelChoiceField, SlugField
77

88
__all__ = (
9-
'CircuitCSVForm',
10-
'CircuitTypeCSVForm',
11-
'ProviderCSVForm',
12-
'ProviderNetworkCSVForm',
9+
'CircuitImportForm',
10+
'CircuitTypeImportForm',
11+
'ProviderImportForm',
12+
'ProviderNetworkImportForm',
1313
)
1414

1515

16-
class ProviderCSVForm(NetBoxModelCSVForm):
16+
class ProviderImportForm(NetBoxModelImportForm):
1717
slug = SlugField()
1818

1919
class Meta:
@@ -23,7 +23,7 @@ class Meta:
2323
)
2424

2525

26-
class ProviderNetworkCSVForm(NetBoxModelCSVForm):
26+
class ProviderNetworkImportForm(NetBoxModelImportForm):
2727
provider = CSVModelChoiceField(
2828
queryset=Provider.objects.all(),
2929
to_field_name='name',
@@ -37,7 +37,7 @@ class Meta:
3737
]
3838

3939

40-
class CircuitTypeCSVForm(NetBoxModelCSVForm):
40+
class CircuitTypeImportForm(NetBoxModelImportForm):
4141
slug = SlugField()
4242

4343
class Meta:
@@ -48,7 +48,7 @@ class Meta:
4848
}
4949

5050

51-
class CircuitCSVForm(NetBoxModelCSVForm):
51+
class CircuitImportForm(NetBoxModelImportForm):
5252
provider = CSVModelChoiceField(
5353
queryset=Provider.objects.all(),
5454
to_field_name='name',

netbox/circuits/views.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class ProviderDeleteView(generic.ObjectDeleteView):
5757

5858
class ProviderBulkImportView(generic.BulkImportView):
5959
queryset = Provider.objects.all()
60-
model_form = forms.ProviderCSVForm
60+
model_form = forms.ProviderImportForm
6161
table = tables.ProviderTable
6262

6363

@@ -122,7 +122,7 @@ class ProviderNetworkDeleteView(generic.ObjectDeleteView):
122122

123123
class ProviderNetworkBulkImportView(generic.BulkImportView):
124124
queryset = ProviderNetwork.objects.all()
125-
model_form = forms.ProviderNetworkCSVForm
125+
model_form = forms.ProviderNetworkImportForm
126126
table = tables.ProviderNetworkTable
127127

128128

@@ -179,7 +179,7 @@ class CircuitTypeDeleteView(generic.ObjectDeleteView):
179179

180180
class CircuitTypeBulkImportView(generic.BulkImportView):
181181
queryset = CircuitType.objects.all()
182-
model_form = forms.CircuitTypeCSVForm
182+
model_form = forms.CircuitTypeImportForm
183183
table = tables.CircuitTypeTable
184184

185185

@@ -231,7 +231,7 @@ class CircuitDeleteView(generic.ObjectDeleteView):
231231

232232
class CircuitBulkImportView(generic.BulkImportView):
233233
queryset = Circuit.objects.all()
234-
model_form = forms.CircuitCSVForm
234+
model_form = forms.CircuitImportForm
235235
table = tables.CircuitTable
236236

237237

0 commit comments

Comments
 (0)