2021-09-27 15:23:12 -04:00
|
|
|
from django import forms
|
2023-07-31 23:52:38 +07:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
2021-09-27 15:23:12 -04:00
|
|
|
|
2023-04-18 16:33:43 -04:00
|
|
|
from circuits.choices import CircuitCommitRateChoices, CircuitStatusChoices
|
2021-09-27 15:23:12 -04:00
|
|
|
from circuits.models import *
|
2022-03-30 17:17:36 -04:00
|
|
|
from ipam.models import ASN
|
2022-01-28 15:48:15 -05:00
|
|
|
from netbox.forms import NetBoxModelBulkEditForm
|
2021-09-27 15:23:12 -04:00
|
|
|
from tenancy.models import Tenant
|
2023-04-14 10:33:53 -04:00
|
|
|
from utilities.forms import add_blank_choice
|
|
|
|
from utilities.forms.fields import CommentField, DynamicModelChoiceField, DynamicModelMultipleChoiceField
|
2023-04-18 16:33:43 -04:00
|
|
|
from utilities.forms.widgets import DatePicker, NumberWithOptions
|
2021-09-27 15:23:12 -04:00
|
|
|
|
|
|
|
__all__ = (
|
|
|
|
'CircuitBulkEditForm',
|
|
|
|
'CircuitTypeBulkEditForm',
|
|
|
|
'ProviderBulkEditForm',
|
2023-03-29 07:27:11 -05:00
|
|
|
'ProviderAccountBulkEditForm',
|
2021-09-27 15:23:12 -04:00
|
|
|
'ProviderNetworkBulkEditForm',
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-01-28 15:48:15 -05:00
|
|
|
class ProviderBulkEditForm(NetBoxModelBulkEditForm):
|
2022-03-30 17:17:36 -04:00
|
|
|
asns = DynamicModelMultipleChoiceField(
|
|
|
|
queryset=ASN.objects.all(),
|
|
|
|
label=_('ASNs'),
|
|
|
|
required=False
|
2021-09-27 15:23:12 -04:00
|
|
|
)
|
2022-11-04 08:28:09 -04:00
|
|
|
description = forms.CharField(
|
2023-07-31 23:52:38 +07:00
|
|
|
label=_('Description'),
|
2022-11-04 08:28:09 -04:00
|
|
|
max_length=200,
|
|
|
|
required=False
|
|
|
|
)
|
2023-07-31 23:52:38 +07:00
|
|
|
comments = CommentField()
|
2021-09-27 15:23:12 -04:00
|
|
|
|
2022-02-01 11:00:18 -05:00
|
|
|
model = Provider
|
2022-02-04 09:59:53 -05:00
|
|
|
fieldsets = (
|
2023-03-29 07:27:11 -05:00
|
|
|
(None, ('asns', 'description')),
|
|
|
|
)
|
|
|
|
nullable_fields = (
|
|
|
|
'asns', 'description', 'comments',
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class ProviderAccountBulkEditForm(NetBoxModelBulkEditForm):
|
|
|
|
provider = DynamicModelChoiceField(
|
2023-07-31 23:52:38 +07:00
|
|
|
label=_('Provider'),
|
2023-03-29 07:27:11 -05:00
|
|
|
queryset=Provider.objects.all(),
|
|
|
|
required=False
|
|
|
|
)
|
|
|
|
description = forms.CharField(
|
2023-07-31 23:52:38 +07:00
|
|
|
label=_('Description'),
|
2023-03-29 07:27:11 -05:00
|
|
|
max_length=200,
|
|
|
|
required=False
|
|
|
|
)
|
2023-07-31 23:52:38 +07:00
|
|
|
comments = CommentField()
|
2023-03-29 07:27:11 -05:00
|
|
|
|
|
|
|
model = ProviderAccount
|
|
|
|
fieldsets = (
|
|
|
|
(None, ('provider', 'description')),
|
2022-02-04 09:59:53 -05:00
|
|
|
)
|
2022-01-31 16:15:40 -05:00
|
|
|
nullable_fields = (
|
2023-03-29 07:27:11 -05:00
|
|
|
'description', 'comments',
|
2022-01-31 16:15:40 -05:00
|
|
|
)
|
2021-09-27 15:23:12 -04:00
|
|
|
|
|
|
|
|
2022-01-28 15:48:15 -05:00
|
|
|
class ProviderNetworkBulkEditForm(NetBoxModelBulkEditForm):
|
2021-09-27 15:23:12 -04:00
|
|
|
provider = DynamicModelChoiceField(
|
2023-07-31 23:52:38 +07:00
|
|
|
label=_('Provider'),
|
2021-09-27 15:23:12 -04:00
|
|
|
queryset=Provider.objects.all(),
|
|
|
|
required=False
|
|
|
|
)
|
2021-12-23 13:50:01 -05:00
|
|
|
service_id = forms.CharField(
|
2021-09-27 15:23:12 -04:00
|
|
|
max_length=100,
|
2022-02-04 09:59:53 -05:00
|
|
|
required=False,
|
2022-11-03 11:58:26 -07:00
|
|
|
label=_('Service ID')
|
2021-09-27 15:23:12 -04:00
|
|
|
)
|
2021-12-23 13:50:01 -05:00
|
|
|
description = forms.CharField(
|
2023-07-31 23:52:38 +07:00
|
|
|
label=_('Description'),
|
2021-12-23 13:50:01 -05:00
|
|
|
max_length=200,
|
|
|
|
required=False
|
|
|
|
)
|
2023-07-31 23:52:38 +07:00
|
|
|
comments = CommentField()
|
2021-09-27 15:23:12 -04:00
|
|
|
|
2022-02-01 11:00:18 -05:00
|
|
|
model = ProviderNetwork
|
2022-02-04 09:59:53 -05:00
|
|
|
fieldsets = (
|
|
|
|
(None, ('provider', 'service_id', 'description')),
|
|
|
|
)
|
2022-01-31 16:15:40 -05:00
|
|
|
nullable_fields = (
|
|
|
|
'service_id', 'description', 'comments',
|
|
|
|
)
|
2021-09-27 15:23:12 -04:00
|
|
|
|
|
|
|
|
2022-01-28 15:48:15 -05:00
|
|
|
class CircuitTypeBulkEditForm(NetBoxModelBulkEditForm):
|
2021-09-27 15:23:12 -04:00
|
|
|
description = forms.CharField(
|
2023-07-31 23:52:38 +07:00
|
|
|
label=_('Description'),
|
2021-09-27 15:23:12 -04:00
|
|
|
max_length=200,
|
|
|
|
required=False
|
|
|
|
)
|
|
|
|
|
2022-02-01 11:00:18 -05:00
|
|
|
model = CircuitType
|
2022-02-04 09:59:53 -05:00
|
|
|
fieldsets = (
|
|
|
|
(None, ('description',)),
|
|
|
|
)
|
2022-01-31 16:15:40 -05:00
|
|
|
nullable_fields = ('description',)
|
2021-09-27 15:23:12 -04:00
|
|
|
|
|
|
|
|
2022-01-28 15:48:15 -05:00
|
|
|
class CircuitBulkEditForm(NetBoxModelBulkEditForm):
|
2021-09-27 15:23:12 -04:00
|
|
|
type = DynamicModelChoiceField(
|
2023-07-31 23:52:38 +07:00
|
|
|
label=_('Type'),
|
2021-09-27 15:23:12 -04:00
|
|
|
queryset=CircuitType.objects.all(),
|
|
|
|
required=False
|
|
|
|
)
|
|
|
|
provider = DynamicModelChoiceField(
|
2023-07-31 23:52:38 +07:00
|
|
|
label=_('Provider'),
|
2021-09-27 15:23:12 -04:00
|
|
|
queryset=Provider.objects.all(),
|
|
|
|
required=False
|
|
|
|
)
|
2023-03-29 07:27:11 -05:00
|
|
|
provider_account = DynamicModelChoiceField(
|
2023-07-31 23:52:38 +07:00
|
|
|
label=_('Provider account'),
|
2023-03-29 07:27:11 -05:00
|
|
|
queryset=ProviderAccount.objects.all(),
|
|
|
|
required=False,
|
|
|
|
query_params={
|
|
|
|
'provider': '$provider'
|
|
|
|
}
|
|
|
|
)
|
2021-09-27 15:23:12 -04:00
|
|
|
status = forms.ChoiceField(
|
2023-07-31 23:52:38 +07:00
|
|
|
label=_('Status'),
|
2021-09-27 15:23:12 -04:00
|
|
|
choices=add_blank_choice(CircuitStatusChoices),
|
|
|
|
required=False,
|
2023-02-16 10:25:51 -05:00
|
|
|
initial=''
|
2021-09-27 15:23:12 -04:00
|
|
|
)
|
|
|
|
tenant = DynamicModelChoiceField(
|
2023-07-31 23:52:38 +07:00
|
|
|
label=_('Tenant'),
|
2021-09-27 15:23:12 -04:00
|
|
|
queryset=Tenant.objects.all(),
|
|
|
|
required=False
|
|
|
|
)
|
2022-06-22 15:09:50 -04:00
|
|
|
install_date = forms.DateField(
|
2023-07-31 23:52:38 +07:00
|
|
|
label=_('Install date'),
|
2022-06-22 15:09:50 -04:00
|
|
|
required=False,
|
|
|
|
widget=DatePicker()
|
|
|
|
)
|
|
|
|
termination_date = forms.DateField(
|
2023-07-31 23:52:38 +07:00
|
|
|
label=_('Termination date'),
|
2022-06-22 15:09:50 -04:00
|
|
|
required=False,
|
|
|
|
widget=DatePicker()
|
|
|
|
)
|
2021-09-27 15:23:12 -04:00
|
|
|
commit_rate = forms.IntegerField(
|
|
|
|
required=False,
|
2023-04-18 16:33:43 -04:00
|
|
|
label=_('Commit rate (Kbps)'),
|
|
|
|
widget=NumberWithOptions(
|
|
|
|
options=CircuitCommitRateChoices
|
|
|
|
)
|
2021-09-27 15:23:12 -04:00
|
|
|
)
|
|
|
|
description = forms.CharField(
|
2023-07-31 23:52:38 +07:00
|
|
|
label=_('Description'),
|
2021-09-27 15:23:12 -04:00
|
|
|
max_length=100,
|
|
|
|
required=False
|
|
|
|
)
|
2023-07-31 23:52:38 +07:00
|
|
|
comments = CommentField()
|
2021-09-27 15:23:12 -04:00
|
|
|
|
2022-02-01 11:00:18 -05:00
|
|
|
model = Circuit
|
2022-02-04 09:59:53 -05:00
|
|
|
fieldsets = (
|
2023-07-31 23:52:38 +07:00
|
|
|
(_('Circuit'), ('provider', 'type', 'status', 'description')),
|
|
|
|
(_('Service Parameters'), ('provider_account', 'install_date', 'termination_date', 'commit_rate')),
|
|
|
|
(_('Tenancy'), ('tenant',)),
|
2022-02-04 09:59:53 -05:00
|
|
|
)
|
2022-01-31 16:15:40 -05:00
|
|
|
nullable_fields = (
|
|
|
|
'tenant', 'commit_rate', 'description', 'comments',
|
|
|
|
)
|