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
b6e50b789c
commit
887dfa0234
@ -1,7 +1,7 @@
|
||||
from django import forms
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.db.models import Q
|
||||
from django.utils.translation import gettext as _
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from extras.choices import CustomFieldFilterLogicChoices, CustomFieldTypeChoices, CustomFieldVisibilityChoices
|
||||
from extras.forms.mixins import CustomFieldsMixin, SavedFiltersMixin
|
||||
@ -28,7 +28,8 @@ class NetBoxModelForm(BootstrapMixin, CustomFieldsMixin, forms.ModelForm):
|
||||
fieldsets = ()
|
||||
tags = DynamicModelMultipleChoiceField(
|
||||
queryset=Tag.objects.all(),
|
||||
required=False
|
||||
required=False,
|
||||
label=_('Tags'),
|
||||
)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
@ -73,10 +74,12 @@ class NetBoxModelImportForm(CSVModelForm, NetBoxModelForm):
|
||||
Base form for creating a NetBox objects from CSV data. Used for bulk importing.
|
||||
"""
|
||||
id = forms.IntegerField(
|
||||
label=_('Id'),
|
||||
required=False,
|
||||
help_text='Numeric ID of an existing object to update (if not creating a new object)'
|
||||
)
|
||||
tags = CSVModelMultipleChoiceField(
|
||||
label=_('Tags'),
|
||||
queryset=Tag.objects.all(),
|
||||
required=False,
|
||||
to_field_name='slug',
|
||||
@ -105,14 +108,17 @@ class NetBoxModelBulkEditForm(BootstrapMixin, CustomFieldsMixin, forms.Form):
|
||||
nullable_fields = ()
|
||||
|
||||
pk = forms.ModelMultipleChoiceField(
|
||||
label=_('Pk'),
|
||||
queryset=None, # Set from self.model on init
|
||||
widget=forms.MultipleHiddenInput
|
||||
)
|
||||
add_tags = DynamicModelMultipleChoiceField(
|
||||
label=_('Add tags'),
|
||||
queryset=Tag.objects.all(),
|
||||
required=False
|
||||
)
|
||||
remove_tags = DynamicModelMultipleChoiceField(
|
||||
label=_('Remove tags'),
|
||||
queryset=Tag.objects.all(),
|
||||
required=False
|
||||
)
|
||||
|
@ -1,4 +1,5 @@
|
||||
from django import forms
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from netbox.forms import NetBoxModelBulkEditForm
|
||||
from tenancy.choices import ContactPriorityChoices
|
||||
@ -22,10 +23,12 @@ __all__ = (
|
||||
|
||||
class TenantGroupBulkEditForm(NetBoxModelBulkEditForm):
|
||||
parent = DynamicModelChoiceField(
|
||||
label=_('Parent'),
|
||||
queryset=TenantGroup.objects.all(),
|
||||
required=False
|
||||
)
|
||||
description = forms.CharField(
|
||||
label=_('Description'),
|
||||
max_length=200,
|
||||
required=False
|
||||
)
|
||||
@ -36,6 +39,7 @@ class TenantGroupBulkEditForm(NetBoxModelBulkEditForm):
|
||||
|
||||
class TenantBulkEditForm(NetBoxModelBulkEditForm):
|
||||
group = DynamicModelChoiceField(
|
||||
label=_('Group'),
|
||||
queryset=TenantGroup.objects.all(),
|
||||
required=False
|
||||
)
|
||||
@ -53,10 +57,12 @@ class TenantBulkEditForm(NetBoxModelBulkEditForm):
|
||||
|
||||
class ContactGroupBulkEditForm(NetBoxModelBulkEditForm):
|
||||
parent = DynamicModelChoiceField(
|
||||
label=_('Parent'),
|
||||
queryset=ContactGroup.objects.all(),
|
||||
required=False
|
||||
)
|
||||
description = forms.CharField(
|
||||
label=_('Desciption'),
|
||||
max_length=200,
|
||||
required=False
|
||||
)
|
||||
@ -70,6 +76,7 @@ class ContactGroupBulkEditForm(NetBoxModelBulkEditForm):
|
||||
|
||||
class ContactRoleBulkEditForm(NetBoxModelBulkEditForm):
|
||||
description = forms.CharField(
|
||||
label=_('Description'),
|
||||
max_length=200,
|
||||
required=False
|
||||
)
|
||||
@ -83,33 +90,40 @@ class ContactRoleBulkEditForm(NetBoxModelBulkEditForm):
|
||||
|
||||
class ContactBulkEditForm(NetBoxModelBulkEditForm):
|
||||
group = DynamicModelChoiceField(
|
||||
label=_('Group'),
|
||||
queryset=ContactGroup.objects.all(),
|
||||
required=False
|
||||
)
|
||||
title = forms.CharField(
|
||||
label=_('Title'),
|
||||
max_length=100,
|
||||
required=False
|
||||
)
|
||||
phone = forms.CharField(
|
||||
label=_('Phone'),
|
||||
max_length=50,
|
||||
required=False
|
||||
)
|
||||
email = forms.EmailField(
|
||||
label=_('Email'),
|
||||
required=False
|
||||
)
|
||||
address = forms.CharField(
|
||||
label=_('Address'),
|
||||
max_length=200,
|
||||
required=False
|
||||
)
|
||||
link = forms.URLField(
|
||||
label=_('Link'),
|
||||
required=False
|
||||
)
|
||||
description = forms.CharField(
|
||||
label=_('Description'),
|
||||
max_length=200,
|
||||
required=False
|
||||
)
|
||||
comments = CommentField(
|
||||
label='Comments'
|
||||
label=_('Comments')
|
||||
)
|
||||
|
||||
model = Contact
|
||||
@ -121,14 +135,17 @@ class ContactBulkEditForm(NetBoxModelBulkEditForm):
|
||||
|
||||
class ContactAssignmentBulkEditForm(NetBoxModelBulkEditForm):
|
||||
contact = DynamicModelChoiceField(
|
||||
label=_('Contact'),
|
||||
queryset=Contact.objects.all(),
|
||||
required=False
|
||||
)
|
||||
role = DynamicModelChoiceField(
|
||||
label=_('Role'),
|
||||
queryset=ContactRole.objects.all(),
|
||||
required=False
|
||||
)
|
||||
priority = forms.ChoiceField(
|
||||
label=_('Priority'),
|
||||
choices=add_blank_choice(ContactPriorityChoices),
|
||||
required=False
|
||||
)
|
||||
|
@ -1,4 +1,4 @@
|
||||
from django.utils.translation import gettext as _
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from netbox.forms import NetBoxModelImportForm
|
||||
from tenancy.models import *
|
||||
from utilities.forms.fields import CSVModelChoiceField, SlugField
|
||||
@ -18,12 +18,15 @@ __all__ = (
|
||||
|
||||
class TenantGroupImportForm(NetBoxModelImportForm):
|
||||
parent = CSVModelChoiceField(
|
||||
label=_('Parent'),
|
||||
queryset=TenantGroup.objects.all(),
|
||||
required=False,
|
||||
to_field_name='name',
|
||||
help_text=_('Parent group')
|
||||
)
|
||||
slug = SlugField()
|
||||
slug = SlugField(
|
||||
label=_('Slug'),
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = TenantGroup
|
||||
@ -31,8 +34,11 @@ class TenantGroupImportForm(NetBoxModelImportForm):
|
||||
|
||||
|
||||
class TenantImportForm(NetBoxModelImportForm):
|
||||
slug = SlugField()
|
||||
slug = SlugField(
|
||||
label=_('Slug'),
|
||||
)
|
||||
group = CSVModelChoiceField(
|
||||
label=_('Group'),
|
||||
queryset=TenantGroup.objects.all(),
|
||||
required=False,
|
||||
to_field_name='name',
|
||||
@ -50,12 +56,15 @@ class TenantImportForm(NetBoxModelImportForm):
|
||||
|
||||
class ContactGroupImportForm(NetBoxModelImportForm):
|
||||
parent = CSVModelChoiceField(
|
||||
label=_('Parent'),
|
||||
queryset=ContactGroup.objects.all(),
|
||||
required=False,
|
||||
to_field_name='name',
|
||||
help_text=_('Parent group')
|
||||
)
|
||||
slug = SlugField()
|
||||
slug = SlugField(
|
||||
label=_('Slug'),
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = ContactGroup
|
||||
@ -63,7 +72,9 @@ class ContactGroupImportForm(NetBoxModelImportForm):
|
||||
|
||||
|
||||
class ContactRoleImportForm(NetBoxModelImportForm):
|
||||
slug = SlugField()
|
||||
slug = SlugField(
|
||||
label=_('Slug'),
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = ContactRole
|
||||
@ -72,6 +83,7 @@ class ContactRoleImportForm(NetBoxModelImportForm):
|
||||
|
||||
class ContactImportForm(NetBoxModelImportForm):
|
||||
group = CSVModelChoiceField(
|
||||
label=_('Group'),
|
||||
queryset=ContactGroup.objects.all(),
|
||||
required=False,
|
||||
to_field_name='name',
|
||||
|
@ -1,6 +1,6 @@
|
||||
from django import forms
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.utils.translation import gettext as _
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from extras.utils import FeatureQuery
|
||||
from netbox.forms import NetBoxModelFilterSetForm
|
||||
@ -84,7 +84,7 @@ class ContactAssignmentFilterForm(NetBoxModelFilterSetForm):
|
||||
model = ContactAssignment
|
||||
fieldsets = (
|
||||
(None, ('q', 'filter_id')),
|
||||
('Assignment', ('content_type_id', 'group_id', 'contact_id', 'role_id', 'priority')),
|
||||
(_('Assignment'), ('content_type_id', 'group_id', 'contact_id', 'role_id', 'priority')),
|
||||
)
|
||||
content_type_id = ContentTypeMultipleChoiceField(
|
||||
queryset=ContentType.objects.all(),
|
||||
@ -108,6 +108,7 @@ class ContactAssignmentFilterForm(NetBoxModelFilterSetForm):
|
||||
label=_('Role')
|
||||
)
|
||||
priority = forms.MultipleChoiceField(
|
||||
label=_('Priority'),
|
||||
choices=ContactPriorityChoices,
|
||||
required=False
|
||||
)
|
||||
|
@ -1,5 +1,5 @@
|
||||
from django import forms
|
||||
from django.utils.translation import gettext as _
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from tenancy.models import *
|
||||
from utilities.forms.fields import DynamicModelChoiceField, DynamicModelMultipleChoiceField
|
||||
@ -13,6 +13,7 @@ __all__ = (
|
||||
|
||||
class TenancyForm(forms.Form):
|
||||
tenant_group = DynamicModelChoiceField(
|
||||
label=_('Tenant group'),
|
||||
queryset=TenantGroup.objects.all(),
|
||||
required=False,
|
||||
null_option='None',
|
||||
@ -21,6 +22,7 @@ class TenancyForm(forms.Form):
|
||||
}
|
||||
)
|
||||
tenant = DynamicModelChoiceField(
|
||||
label=_('Tenant'),
|
||||
queryset=Tenant.objects.all(),
|
||||
required=False,
|
||||
query_params={
|
||||
|
@ -1,4 +1,5 @@
|
||||
from django import forms
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from netbox.forms import NetBoxModelForm
|
||||
from tenancy.models import *
|
||||
@ -21,13 +22,16 @@ __all__ = (
|
||||
|
||||
class TenantGroupForm(NetBoxModelForm):
|
||||
parent = DynamicModelChoiceField(
|
||||
label=_('Parent'),
|
||||
queryset=TenantGroup.objects.all(),
|
||||
required=False
|
||||
)
|
||||
slug = SlugField()
|
||||
slug = SlugField(
|
||||
label=_('Slug'),
|
||||
)
|
||||
|
||||
fieldsets = (
|
||||
('Tenant Group', (
|
||||
(_('Tenant Group'), (
|
||||
'parent', 'name', 'slug', 'description', 'tags',
|
||||
)),
|
||||
)
|
||||
@ -40,15 +44,20 @@ class TenantGroupForm(NetBoxModelForm):
|
||||
|
||||
|
||||
class TenantForm(NetBoxModelForm):
|
||||
slug = SlugField()
|
||||
slug = SlugField(
|
||||
label=_('Slug'),
|
||||
)
|
||||
group = DynamicModelChoiceField(
|
||||
label=_('Group'),
|
||||
queryset=TenantGroup.objects.all(),
|
||||
required=False
|
||||
)
|
||||
comments = CommentField()
|
||||
comments = CommentField(
|
||||
label=_('Comments'),
|
||||
)
|
||||
|
||||
fieldsets = (
|
||||
('Tenant', ('name', 'slug', 'group', 'description', 'tags')),
|
||||
(_('Tenant'), ('name', 'slug', 'group', 'description', 'tags')),
|
||||
)
|
||||
|
||||
class Meta:
|
||||
@ -64,13 +73,16 @@ class TenantForm(NetBoxModelForm):
|
||||
|
||||
class ContactGroupForm(NetBoxModelForm):
|
||||
parent = DynamicModelChoiceField(
|
||||
label=_('Parent'),
|
||||
queryset=ContactGroup.objects.all(),
|
||||
required=False
|
||||
)
|
||||
slug = SlugField()
|
||||
slug = SlugField(
|
||||
label=_('Slug'),
|
||||
)
|
||||
|
||||
fieldsets = (
|
||||
('Contact Group', (
|
||||
(_('Contact Group'), (
|
||||
'parent', 'name', 'slug', 'description', 'tags',
|
||||
)),
|
||||
)
|
||||
@ -81,10 +93,12 @@ class ContactGroupForm(NetBoxModelForm):
|
||||
|
||||
|
||||
class ContactRoleForm(NetBoxModelForm):
|
||||
slug = SlugField()
|
||||
slug = SlugField(
|
||||
label=_('Slug'),
|
||||
)
|
||||
|
||||
fieldsets = (
|
||||
('Contact Role', (
|
||||
(_('Contact Role'), (
|
||||
'name', 'slug', 'description', 'tags',
|
||||
)),
|
||||
)
|
||||
@ -96,13 +110,16 @@ class ContactRoleForm(NetBoxModelForm):
|
||||
|
||||
class ContactForm(NetBoxModelForm):
|
||||
group = DynamicModelChoiceField(
|
||||
label=_('Group'),
|
||||
queryset=ContactGroup.objects.all(),
|
||||
required=False
|
||||
)
|
||||
comments = CommentField()
|
||||
comments = CommentField(
|
||||
label=_('Comments'),
|
||||
)
|
||||
|
||||
fieldsets = (
|
||||
('Contact', ('group', 'name', 'title', 'phone', 'email', 'address', 'link', 'description', 'tags')),
|
||||
(_('Contact'), ('group', 'name', 'title', 'phone', 'email', 'address', 'link', 'description', 'tags')),
|
||||
)
|
||||
|
||||
class Meta:
|
||||
@ -117,6 +134,7 @@ class ContactForm(NetBoxModelForm):
|
||||
|
||||
class ContactAssignmentForm(BootstrapMixin, forms.ModelForm):
|
||||
group = DynamicModelChoiceField(
|
||||
label=_('Group'),
|
||||
queryset=ContactGroup.objects.all(),
|
||||
required=False,
|
||||
initial_params={
|
||||
@ -124,12 +142,14 @@ class ContactAssignmentForm(BootstrapMixin, forms.ModelForm):
|
||||
}
|
||||
)
|
||||
contact = DynamicModelChoiceField(
|
||||
label=_('Contact'),
|
||||
queryset=Contact.objects.all(),
|
||||
query_params={
|
||||
'group_id': '$group'
|
||||
}
|
||||
)
|
||||
role = DynamicModelChoiceField(
|
||||
label=_('Role'),
|
||||
queryset=ContactRole.objects.all()
|
||||
)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user