mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Closes #1983: Enable regular expressions when bulk renaming device components
This commit is contained in:
@@ -58,6 +58,22 @@ class BulkRenameForm(forms.Form):
|
||||
"""
|
||||
find = forms.CharField()
|
||||
replace = forms.CharField()
|
||||
use_regex = forms.BooleanField(
|
||||
required=False,
|
||||
initial=True,
|
||||
label='Use regular expressions'
|
||||
)
|
||||
|
||||
def clean(self):
|
||||
|
||||
# Validate regular expression in "find" field
|
||||
if self.cleaned_data['use_regex']:
|
||||
try:
|
||||
re.compile(self.cleaned_data['find'])
|
||||
except re.error:
|
||||
raise forms.ValidationError({
|
||||
'find': "Invalid regular expression"
|
||||
})
|
||||
|
||||
|
||||
#
|
||||
|
||||
Reference in New Issue
Block a user