mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-25 00:36:11 -06:00
13149 add gettext_lazy to forms
This commit is contained in:
parent
887dfa0234
commit
230d80a31d
@ -1,5 +1,6 @@
|
||||
from django import forms
|
||||
from django.contrib.postgres.forms import SimpleArrayField
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from ..utils import parse_numeric_range
|
||||
|
||||
@ -12,8 +13,8 @@ class NumericArrayField(SimpleArrayField):
|
||||
|
||||
def clean(self, value):
|
||||
if value and not self.to_python(value):
|
||||
raise forms.ValidationError(f'Invalid list ({value}). '
|
||||
f'Must be numeric and ranges must be in ascending order')
|
||||
raise forms.ValidationError(_('Invalid list ({value}). '
|
||||
'Must be numeric and ranges must be in ascending order').format(value=value))
|
||||
return super().clean(value)
|
||||
|
||||
def to_python(self, value):
|
||||
|
@ -1,4 +1,5 @@
|
||||
from django import forms
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.core.exceptions import MultipleObjectsReturned, ObjectDoesNotExist
|
||||
from django.db.models import Q
|
||||
@ -40,7 +41,7 @@ class CSVMultipleChoiceField(CSVChoicesMixin, forms.MultipleChoiceField):
|
||||
if not value:
|
||||
return []
|
||||
if not isinstance(value, str):
|
||||
raise forms.ValidationError(f"Invalid value for a multiple choice field: {value}")
|
||||
raise forms.ValidationError(_("Invalid value for a multiple choice field: {value}").format(value=value))
|
||||
return value.split(',')
|
||||
|
||||
|
||||
@ -53,7 +54,7 @@ class CSVModelChoiceField(forms.ModelChoiceField):
|
||||
Extends Django's `ModelChoiceField` to provide additional validation for CSV values.
|
||||
"""
|
||||
default_error_messages = {
|
||||
'invalid_choice': 'Object not found: %(value)s',
|
||||
'invalid_choice': _('Object not found: %(value)s'),
|
||||
}
|
||||
|
||||
def to_python(self, value):
|
||||
@ -61,7 +62,7 @@ class CSVModelChoiceField(forms.ModelChoiceField):
|
||||
return super().to_python(value)
|
||||
except MultipleObjectsReturned:
|
||||
raise forms.ValidationError(
|
||||
f'"{value}" is not a unique value for this field; multiple objects were found'
|
||||
_('"{value}" is not a unique value for this field; multiple objects were found').format(value=value)
|
||||
)
|
||||
|
||||
|
||||
@ -70,7 +71,7 @@ class CSVModelMultipleChoiceField(forms.ModelMultipleChoiceField):
|
||||
Extends Django's `ModelMultipleChoiceField` to support comma-separated values.
|
||||
"""
|
||||
default_error_messages = {
|
||||
'invalid_choice': 'Object not found: %(value)s',
|
||||
'invalid_choice': _('Object not found: %(value)s'),
|
||||
}
|
||||
|
||||
def clean(self, value):
|
||||
@ -93,11 +94,11 @@ class CSVContentTypeField(CSVModelChoiceField):
|
||||
try:
|
||||
app_label, model = value.split('.')
|
||||
except ValueError:
|
||||
raise forms.ValidationError(f'Object type must be specified as "<app>.<model>"')
|
||||
raise forms.ValidationError(_('Object type must be specified as "<app>.<model>"'))
|
||||
try:
|
||||
return self.queryset.get(app_label=app_label, model=model)
|
||||
except ObjectDoesNotExist:
|
||||
raise forms.ValidationError(f'Invalid object type')
|
||||
raise forms.ValidationError(_('Invalid object type'))
|
||||
|
||||
|
||||
class CSVMultipleContentTypeField(forms.ModelMultipleChoiceField):
|
||||
|
@ -1,7 +1,7 @@
|
||||
import re
|
||||
|
||||
from django import forms
|
||||
from django.utils.translation import gettext as _
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from utilities.forms.constants import *
|
||||
from utilities.forms.utils import expand_alphanumeric_pattern, expand_ipaddress_pattern
|
||||
@ -21,10 +21,10 @@ class ExpandableNameField(forms.CharField):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
if not self.help_text:
|
||||
self.help_text = """
|
||||
self.help_text = _("""
|
||||
Alphanumeric ranges are supported for bulk creation. Mixed cases and types within a single range
|
||||
are not supported (example: <code>[ge,xe]-0/0/[0-9]</code>).
|
||||
"""
|
||||
""")
|
||||
|
||||
def to_python(self, value):
|
||||
if not value:
|
||||
|
Loading…
Reference in New Issue
Block a user