mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Add model validator to prevent illegal names for PartParameterTemplate
(cherry picked from commit 93805a87e0
)
This commit is contained in:
parent
512eceb2a6
commit
6d42cfab75
@ -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)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user