1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

170 lines
4.4 KiB
Python
Raw Normal View History

2021-09-27 15:23:12 -04:00
from django import forms
from django.utils.translation import gettext_lazy as _
2021-09-27 15:23:12 -04:00
from circuits.choices import CircuitCommitRateChoices, CircuitStatusChoices
2021-09-27 15:23:12 -04:00
from circuits.models import *
from ipam.models import ASN
from netbox.forms import NetBoxModelBulkEditForm
2021-09-27 15:23:12 -04:00
from tenancy.models import Tenant
from utilities.forms import add_blank_choice
from utilities.forms.fields import CommentField, DynamicModelChoiceField, DynamicModelMultipleChoiceField
from utilities.forms.widgets import DatePicker, NumberWithOptions
2021-09-27 15:23:12 -04:00
__all__ = (
'CircuitBulkEditForm',
'CircuitTypeBulkEditForm',
'ProviderBulkEditForm',
'ProviderAccountBulkEditForm',
2021-09-27 15:23:12 -04:00
'ProviderNetworkBulkEditForm',
)
class ProviderBulkEditForm(NetBoxModelBulkEditForm):
asns = DynamicModelMultipleChoiceField(
queryset=ASN.objects.all(),
label=_('ASNs'),
required=False
2021-09-27 15:23:12 -04:00
)
description = forms.CharField(
label=_('Description'),
max_length=200,
required=False
)
comments = CommentField()
2021-09-27 15:23:12 -04:00
model = Provider
fieldsets = (
(None, ('asns', 'description')),
)
nullable_fields = (
'asns', 'description', 'comments',
)
class ProviderAccountBulkEditForm(NetBoxModelBulkEditForm):
provider = DynamicModelChoiceField(
label=_('Provider'),
queryset=Provider.objects.all(),
required=False
)
description = forms.CharField(
label=_('Description'),
max_length=200,
required=False
)
comments = CommentField()
model = ProviderAccount
fieldsets = (
(None, ('provider', 'description')),
)
nullable_fields = (
'description', 'comments',
)
2021-09-27 15:23:12 -04:00
class ProviderNetworkBulkEditForm(NetBoxModelBulkEditForm):
2021-09-27 15:23:12 -04:00
provider = DynamicModelChoiceField(
label=_('Provider'),
2021-09-27 15:23:12 -04:00
queryset=Provider.objects.all(),
required=False
)
service_id = forms.CharField(
2021-09-27 15:23:12 -04:00
max_length=100,
required=False,
label=_('Service ID')
2021-09-27 15:23:12 -04:00
)
description = forms.CharField(
label=_('Description'),
max_length=200,
required=False
)
comments = CommentField()
2021-09-27 15:23:12 -04:00
model = ProviderNetwork
fieldsets = (
(None, ('provider', 'service_id', 'description')),
)
nullable_fields = (
'service_id', 'description', 'comments',
)
2021-09-27 15:23:12 -04:00
class CircuitTypeBulkEditForm(NetBoxModelBulkEditForm):
2021-09-27 15:23:12 -04:00
description = forms.CharField(
label=_('Description'),
2021-09-27 15:23:12 -04:00
max_length=200,
required=False
)
model = CircuitType
fieldsets = (
(None, ('description',)),
)
nullable_fields = ('description',)
2021-09-27 15:23:12 -04:00
class CircuitBulkEditForm(NetBoxModelBulkEditForm):
2021-09-27 15:23:12 -04:00
type = DynamicModelChoiceField(
label=_('Type'),
2021-09-27 15:23:12 -04:00
queryset=CircuitType.objects.all(),
required=False
)
provider = DynamicModelChoiceField(
label=_('Provider'),
2021-09-27 15:23:12 -04:00
queryset=Provider.objects.all(),
required=False
)
provider_account = DynamicModelChoiceField(
label=_('Provider account'),
queryset=ProviderAccount.objects.all(),
required=False,
query_params={
'provider': '$provider'
}
)
2021-09-27 15:23:12 -04:00
status = forms.ChoiceField(
label=_('Status'),
2021-09-27 15:23:12 -04:00
choices=add_blank_choice(CircuitStatusChoices),
required=False,
initial=''
2021-09-27 15:23:12 -04:00
)
tenant = DynamicModelChoiceField(
label=_('Tenant'),
2021-09-27 15:23:12 -04:00
queryset=Tenant.objects.all(),
required=False
)
install_date = forms.DateField(
label=_('Install date'),
required=False,
widget=DatePicker()
)
termination_date = forms.DateField(
label=_('Termination date'),
required=False,
widget=DatePicker()
)
2021-09-27 15:23:12 -04:00
commit_rate = forms.IntegerField(
required=False,
label=_('Commit rate (Kbps)'),
widget=NumberWithOptions(
options=CircuitCommitRateChoices
)
2021-09-27 15:23:12 -04:00
)
description = forms.CharField(
label=_('Description'),
2021-09-27 15:23:12 -04:00
max_length=100,
required=False
)
comments = CommentField()
2021-09-27 15:23:12 -04:00
model = Circuit
fieldsets = (
(_('Circuit'), ('provider', 'type', 'status', 'description')),
(_('Service Parameters'), ('provider_account', 'install_date', 'termination_date', 'commit_rate')),
(_('Tenancy'), ('tenant',)),
)
nullable_fields = (
'tenant', 'commit_rate', 'description', 'comments',
)