Add model validator to prevent illegal names for PartParameterTemplate

(cherry picked from commit 93805a87e0)
This commit is contained in:
Oliver Walters 2021-08-07 21:08:08 +10:00
parent 512eceb2a6
commit 6d42cfab75

View File

@ -2143,6 +2143,16 @@ class PartTestTemplate(models.Model):
) )
def validate_template_name(name):
"""
Prevent illegal characters in "name" field for PartParameterTemplate
"""
for c in "!@#$%^&*()<>{}[].,?/\|~`_+-=\'\"":
if c in str(name):
raise ValidationError(_(f"Illegal character in template name ({c})"))
class PartParameterTemplate(models.Model): class PartParameterTemplate(models.Model):
""" """
A PartParameterTemplate provides a template for key:value pairs for extra A PartParameterTemplate provides a template for key:value pairs for extra
@ -2181,7 +2191,15 @@ class PartParameterTemplate(models.Model):
except PartParameterTemplate.DoesNotExist: except PartParameterTemplate.DoesNotExist:
pass pass
name = models.CharField(max_length=100, verbose_name=_('Name'), help_text=_('Parameter Name'), unique=True) name = models.CharField(
max_length=100,
verbose_name=_('Name'),
help_text=_('Parameter Name'),
unique=True,
validators=[
validate_template_name,
]
)
units = models.CharField(max_length=25, verbose_name=_('Units'), help_text=_('Parameter Units'), blank=True) units = models.CharField(max_length=25, verbose_name=_('Units'), help_text=_('Parameter Units'), blank=True)