|
1 |
| -import re |
2 |
| - |
3 | 1 | from django import forms
|
4 | 2 | from django.conf import settings
|
5 | 3 | from django.core.exceptions import MultipleObjectsReturned, ObjectDoesNotExist, ValidationError
|
|
11 | 9 | from ipam.models import IPAddress, Prefix, ASN
|
12 | 10 | from ipam.formfields import IPNetworkFormField
|
13 | 11 | from utilities.forms.fields import (
|
14 |
| - DynamicModelChoiceField, |
| 12 | + DynamicModelChoiceField, CSVModelChoiceField, |
15 | 13 | DynamicModelMultipleChoiceField,
|
16 |
| - TagFilterField |
| 14 | + TagFilterField, CSVChoiceField, |
17 | 15 | )
|
18 | 16 | from utilities.forms.widgets import APISelect, APISelectMultiple
|
19 |
| -from netbox.forms import NetBoxModelForm, NetBoxModelBulkEditForm, NetBoxModelFilterSetForm |
| 17 | +from netbox.forms import NetBoxModelForm, NetBoxModelBulkEditForm, NetBoxModelFilterSetForm, NetBoxModelImportForm |
20 | 18 |
|
21 | 19 | from .models import (
|
22 | 20 | Community, BGPSession, RoutingPolicy, BGPPeerGroup,
|
@@ -93,6 +91,23 @@ class CommunityBulkEditForm(NetBoxModelBulkEditForm):
|
93 | 91 | 'tenant', 'description',
|
94 | 92 | ]
|
95 | 93 |
|
| 94 | +class CommunityImportForm(NetBoxModelImportForm): |
| 95 | + tenant = CSVModelChoiceField( |
| 96 | + queryset=Tenant.objects.all(), |
| 97 | + required=False, |
| 98 | + to_field_name='name', |
| 99 | + help_text=_('Assigned tenant') |
| 100 | + ) |
| 101 | + |
| 102 | + status = CSVChoiceField( |
| 103 | + choices=CommunityStatusChoices, |
| 104 | + help_text=_('Operational status') |
| 105 | + ) |
| 106 | + |
| 107 | + class Meta: |
| 108 | + model = Community |
| 109 | + fields = ('value', 'description', 'tags') |
| 110 | + |
96 | 111 |
|
97 | 112 | class BGPSessionForm(NetBoxModelForm):
|
98 | 113 | name = forms.CharField(
|
|
0 commit comments