mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-24 16:26:09 -06:00
13149 add gettext_lazy to forms
This commit is contained in:
parent
0c2e3ff898
commit
6f0b7fa133
@ -1,5 +1,5 @@
|
||||
from django import forms
|
||||
from django.utils.translation import gettext as _
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from circuits.choices import CircuitCommitRateChoices, CircuitStatusChoices
|
||||
from circuits.models import *
|
||||
@ -26,6 +26,7 @@ class ProviderBulkEditForm(NetBoxModelBulkEditForm):
|
||||
required=False
|
||||
)
|
||||
description = forms.CharField(
|
||||
label=_('Description'),
|
||||
max_length=200,
|
||||
required=False
|
||||
)
|
||||
@ -44,10 +45,12 @@ class ProviderBulkEditForm(NetBoxModelBulkEditForm):
|
||||
|
||||
class ProviderAccountBulkEditForm(NetBoxModelBulkEditForm):
|
||||
provider = DynamicModelChoiceField(
|
||||
label=_('Provider'),
|
||||
queryset=Provider.objects.all(),
|
||||
required=False
|
||||
)
|
||||
description = forms.CharField(
|
||||
label=_('Description'),
|
||||
max_length=200,
|
||||
required=False
|
||||
)
|
||||
@ -66,6 +69,7 @@ class ProviderAccountBulkEditForm(NetBoxModelBulkEditForm):
|
||||
|
||||
class ProviderNetworkBulkEditForm(NetBoxModelBulkEditForm):
|
||||
provider = DynamicModelChoiceField(
|
||||
label=_('Provider'),
|
||||
queryset=Provider.objects.all(),
|
||||
required=False
|
||||
)
|
||||
@ -75,6 +79,7 @@ class ProviderNetworkBulkEditForm(NetBoxModelBulkEditForm):
|
||||
label=_('Service ID')
|
||||
)
|
||||
description = forms.CharField(
|
||||
label=_('Description'),
|
||||
max_length=200,
|
||||
required=False
|
||||
)
|
||||
@ -93,6 +98,7 @@ class ProviderNetworkBulkEditForm(NetBoxModelBulkEditForm):
|
||||
|
||||
class CircuitTypeBulkEditForm(NetBoxModelBulkEditForm):
|
||||
description = forms.CharField(
|
||||
label=_('Description'),
|
||||
max_length=200,
|
||||
required=False
|
||||
)
|
||||
@ -106,14 +112,17 @@ class CircuitTypeBulkEditForm(NetBoxModelBulkEditForm):
|
||||
|
||||
class CircuitBulkEditForm(NetBoxModelBulkEditForm):
|
||||
type = DynamicModelChoiceField(
|
||||
label=_('Type'),
|
||||
queryset=CircuitType.objects.all(),
|
||||
required=False
|
||||
)
|
||||
provider = DynamicModelChoiceField(
|
||||
label=_('Provider'),
|
||||
queryset=Provider.objects.all(),
|
||||
required=False
|
||||
)
|
||||
provider_account = DynamicModelChoiceField(
|
||||
label=_('Provider account'),
|
||||
queryset=ProviderAccount.objects.all(),
|
||||
required=False,
|
||||
query_params={
|
||||
@ -121,19 +130,23 @@ class CircuitBulkEditForm(NetBoxModelBulkEditForm):
|
||||
}
|
||||
)
|
||||
status = forms.ChoiceField(
|
||||
label=_('Status'),
|
||||
choices=add_blank_choice(CircuitStatusChoices),
|
||||
required=False,
|
||||
initial=''
|
||||
)
|
||||
tenant = DynamicModelChoiceField(
|
||||
label=_('Tenant'),
|
||||
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()
|
||||
)
|
||||
@ -145,6 +158,7 @@ class CircuitBulkEditForm(NetBoxModelBulkEditForm):
|
||||
)
|
||||
)
|
||||
description = forms.CharField(
|
||||
label=_('Description'),
|
||||
max_length=100,
|
||||
required=False
|
||||
)
|
||||
|
@ -3,7 +3,7 @@ from django import forms
|
||||
from circuits.choices import CircuitStatusChoices
|
||||
from circuits.models import *
|
||||
from dcim.models import Site
|
||||
from django.utils.translation import gettext as _
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from netbox.forms import NetBoxModelImportForm
|
||||
from tenancy.models import Tenant
|
||||
from utilities.forms import BootstrapMixin
|
||||
@ -31,6 +31,7 @@ class ProviderImportForm(NetBoxModelImportForm):
|
||||
|
||||
class ProviderAccountImportForm(NetBoxModelImportForm):
|
||||
provider = CSVModelChoiceField(
|
||||
label=_('Provider'),
|
||||
queryset=Provider.objects.all(),
|
||||
to_field_name='name',
|
||||
help_text=_('Assigned provider')
|
||||
@ -45,6 +46,7 @@ class ProviderAccountImportForm(NetBoxModelImportForm):
|
||||
|
||||
class ProviderNetworkImportForm(NetBoxModelImportForm):
|
||||
provider = CSVModelChoiceField(
|
||||
label=_('Provider'),
|
||||
queryset=Provider.objects.all(),
|
||||
to_field_name='name',
|
||||
help_text=_('Assigned provider')
|
||||
@ -58,7 +60,9 @@ class ProviderNetworkImportForm(NetBoxModelImportForm):
|
||||
|
||||
|
||||
class CircuitTypeImportForm(NetBoxModelImportForm):
|
||||
slug = SlugField()
|
||||
slug = SlugField(
|
||||
label=_('Slug'),
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = CircuitType
|
||||
@ -67,26 +71,31 @@ class CircuitTypeImportForm(NetBoxModelImportForm):
|
||||
|
||||
class CircuitImportForm(NetBoxModelImportForm):
|
||||
provider = CSVModelChoiceField(
|
||||
label=_('Provider'),
|
||||
queryset=Provider.objects.all(),
|
||||
to_field_name='name',
|
||||
help_text=_('Assigned provider')
|
||||
)
|
||||
provider_account = CSVModelChoiceField(
|
||||
label=_('Provider account'),
|
||||
queryset=ProviderAccount.objects.all(),
|
||||
to_field_name='name',
|
||||
help_text=_('Assigned provider account'),
|
||||
required=False
|
||||
)
|
||||
type = CSVModelChoiceField(
|
||||
label=_('Type'),
|
||||
queryset=CircuitType.objects.all(),
|
||||
to_field_name='name',
|
||||
help_text=_('Type of circuit')
|
||||
)
|
||||
status = CSVChoiceField(
|
||||
label=_('Status'),
|
||||
choices=CircuitStatusChoices,
|
||||
help_text=_('Operational status')
|
||||
)
|
||||
tenant = CSVModelChoiceField(
|
||||
label=_('Tenant'),
|
||||
queryset=Tenant.objects.all(),
|
||||
required=False,
|
||||
to_field_name='name',
|
||||
@ -103,11 +112,13 @@ class CircuitImportForm(NetBoxModelImportForm):
|
||||
|
||||
class CircuitTerminationImportForm(BootstrapMixin, forms.ModelForm):
|
||||
site = CSVModelChoiceField(
|
||||
label=_('Site'),
|
||||
queryset=Site.objects.all(),
|
||||
to_field_name='name',
|
||||
required=False
|
||||
)
|
||||
provider_network = CSVModelChoiceField(
|
||||
label=_('Provider network'),
|
||||
queryset=ProviderNetwork.objects.all(),
|
||||
to_field_name='name',
|
||||
required=False
|
||||
|
@ -70,6 +70,7 @@ class ProviderAccountFilterForm(NetBoxModelFilterSetForm):
|
||||
label=_('Provider')
|
||||
)
|
||||
account = forms.CharField(
|
||||
label=_('Account'),
|
||||
required=False
|
||||
)
|
||||
tag = TagFilterField(model)
|
||||
@ -87,6 +88,7 @@ class ProviderNetworkFilterForm(NetBoxModelFilterSetForm):
|
||||
label=_('Provider')
|
||||
)
|
||||
service_id = forms.CharField(
|
||||
label=_('Service id'),
|
||||
max_length=100,
|
||||
required=False
|
||||
)
|
||||
@ -135,6 +137,7 @@ class CircuitFilterForm(TenancyFilterForm, ContactModelFilterForm, NetBoxModelFi
|
||||
label=_('Provider network')
|
||||
)
|
||||
status = forms.MultipleChoiceField(
|
||||
label=_('Status'),
|
||||
choices=CircuitStatusChoices,
|
||||
required=False
|
||||
)
|
||||
@ -158,10 +161,12 @@ class CircuitFilterForm(TenancyFilterForm, ContactModelFilterForm, NetBoxModelFi
|
||||
label=_('Site')
|
||||
)
|
||||
install_date = forms.DateField(
|
||||
label=_('Install date'),
|
||||
required=False,
|
||||
widget=DatePicker
|
||||
)
|
||||
termination_date = forms.DateField(
|
||||
label=_('Termination date'),
|
||||
required=False,
|
||||
widget=DatePicker
|
||||
)
|
||||
|
@ -1,4 +1,4 @@
|
||||
from django.utils.translation import gettext as _
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from circuits.choices import CircuitCommitRateChoices, CircuitTerminationPortSpeedChoices
|
||||
from circuits.models import *
|
||||
@ -26,7 +26,9 @@ class ProviderForm(NetBoxModelForm):
|
||||
label=_('ASNs'),
|
||||
required=False
|
||||
)
|
||||
comments = CommentField()
|
||||
comments = CommentField(
|
||||
label=_('Comments'),
|
||||
)
|
||||
|
||||
fieldsets = (
|
||||
('Provider', ('name', 'slug', 'asns', 'description', 'tags')),
|
||||
@ -41,9 +43,12 @@ class ProviderForm(NetBoxModelForm):
|
||||
|
||||
class ProviderAccountForm(NetBoxModelForm):
|
||||
provider = DynamicModelChoiceField(
|
||||
label=_('Provider'),
|
||||
queryset=Provider.objects.all()
|
||||
)
|
||||
comments = CommentField()
|
||||
comments = CommentField(
|
||||
label=_('Comments'),
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = ProviderAccount
|
||||
@ -54,9 +59,12 @@ class ProviderAccountForm(NetBoxModelForm):
|
||||
|
||||
class ProviderNetworkForm(NetBoxModelForm):
|
||||
provider = DynamicModelChoiceField(
|
||||
label=_('Provider'),
|
||||
queryset=Provider.objects.all()
|
||||
)
|
||||
comments = CommentField()
|
||||
comments = CommentField(
|
||||
label=_('Comments'),
|
||||
)
|
||||
|
||||
fieldsets = (
|
||||
('Provider Network', ('provider', 'name', 'service_id', 'description', 'tags')),
|
||||
@ -70,7 +78,9 @@ class ProviderNetworkForm(NetBoxModelForm):
|
||||
|
||||
|
||||
class CircuitTypeForm(NetBoxModelForm):
|
||||
slug = SlugField()
|
||||
slug = SlugField(
|
||||
label=_('Slug'),
|
||||
)
|
||||
|
||||
fieldsets = (
|
||||
('Circuit Type', (
|
||||
@ -87,10 +97,12 @@ class CircuitTypeForm(NetBoxModelForm):
|
||||
|
||||
class CircuitForm(TenancyForm, NetBoxModelForm):
|
||||
provider = DynamicModelChoiceField(
|
||||
label=_('Provider'),
|
||||
queryset=Provider.objects.all(),
|
||||
selector=True
|
||||
)
|
||||
provider_account = DynamicModelChoiceField(
|
||||
label=_('Provider account'),
|
||||
queryset=ProviderAccount.objects.all(),
|
||||
required=False,
|
||||
query_params={
|
||||
@ -125,15 +137,18 @@ class CircuitForm(TenancyForm, NetBoxModelForm):
|
||||
|
||||
class CircuitTerminationForm(NetBoxModelForm):
|
||||
circuit = DynamicModelChoiceField(
|
||||
label=_('Circuit'),
|
||||
queryset=Circuit.objects.all(),
|
||||
selector=True
|
||||
)
|
||||
site = DynamicModelChoiceField(
|
||||
label=_('Site'),
|
||||
queryset=Site.objects.all(),
|
||||
required=False,
|
||||
selector=True
|
||||
)
|
||||
provider_network = DynamicModelChoiceField(
|
||||
label=_('Provider network'),
|
||||
queryset=ProviderNetwork.objects.all(),
|
||||
required=False,
|
||||
selector=True
|
||||
|
@ -4,7 +4,7 @@ from django import forms
|
||||
from django.db.models import Count
|
||||
from django.forms.fields import JSONField as _JSONField, InvalidJSONInput
|
||||
from django.templatetags.static import static
|
||||
from django.utils.translation import gettext as _
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from netaddr import AddrFormatError, EUI
|
||||
|
||||
from utilities.forms import widgets
|
||||
@ -26,11 +26,11 @@ class CommentField(forms.CharField):
|
||||
A textarea with support for Markdown rendering. Exists mostly just to add a standard `help_text`.
|
||||
"""
|
||||
widget = widgets.MarkdownWidget
|
||||
help_text = f"""
|
||||
help_text = _("""
|
||||
<i class="mdi mdi-information-outline"></i>
|
||||
<a href="{static('docs/reference/markdown/')}" target="_blank" tabindex="-1">
|
||||
<a href="{url}" target="_blank" tabindex="-1">
|
||||
Markdown</a> syntax is supported
|
||||
"""
|
||||
""").format(url=static('docs/reference/markdown/'))
|
||||
|
||||
def __init__(self, *, help_text=help_text, required=False, **kwargs):
|
||||
super().__init__(help_text=help_text, required=required, **kwargs)
|
||||
@ -77,7 +77,7 @@ class TagFilterField(forms.MultipleChoiceField):
|
||||
]
|
||||
|
||||
# Choices are fetched each time the form is initialized
|
||||
super().__init__(label='Tags', choices=get_choices, required=False, *args, **kwargs)
|
||||
super().__init__(label=_('Tags'), choices=get_choices, required=False, *args, **kwargs)
|
||||
|
||||
|
||||
class LaxURLField(forms.URLField):
|
||||
@ -113,7 +113,7 @@ class MACAddressField(forms.Field):
|
||||
"""
|
||||
widget = forms.CharField
|
||||
default_error_messages = {
|
||||
'invalid': 'MAC address must be in EUI-48 format',
|
||||
'invalid': _('MAC address must be in EUI-48 format'),
|
||||
}
|
||||
|
||||
def to_python(self, value):
|
||||
|
Loading…
Reference in New Issue
Block a user