mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
IPN must match regex validator (if one is provided)
This commit is contained in:
parent
356b6cf15b
commit
9cef038d6a
@ -6,6 +6,10 @@ from django.conf import settings
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from common.models import InvenTreeSetting
|
||||
|
||||
import re
|
||||
|
||||
|
||||
def allowable_url_schemes():
|
||||
""" Return the list of allowable URL schemes.
|
||||
@ -35,6 +39,17 @@ def validate_part_name(value):
|
||||
_('Invalid character in part name')
|
||||
)
|
||||
|
||||
def validate_part_ipn(value):
|
||||
""" Validate the Part IPN against regex rule """
|
||||
|
||||
pattern = InvenTreeSetting.get_setting('part_ipn_regex')
|
||||
|
||||
if pattern:
|
||||
match = re.search(pattern, value)
|
||||
|
||||
if match is None:
|
||||
raise ValidationError(_('IPN must match regex pattern') + " '{pat}'".format(pat=pattern))
|
||||
|
||||
|
||||
def validate_tree_name(value):
|
||||
""" Prevent illegal characters in tree item names """
|
||||
|
19
InvenTree/part/migrations/0028_auto_20200203_1007.py
Normal file
19
InvenTree/part/migrations/0028_auto_20200203_1007.py
Normal file
@ -0,0 +1,19 @@
|
||||
# Generated by Django 2.2.9 on 2020-02-03 10:07
|
||||
|
||||
import InvenTree.validators
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('part', '0027_auto_20200202_1024'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='part',
|
||||
name='IPN',
|
||||
field=models.CharField(blank=True, help_text='Internal Part Number', max_length=100, validators=[InvenTree.validators.validate_part_ipn]),
|
||||
),
|
||||
]
|
@ -349,7 +349,7 @@ class Part(models.Model):
|
||||
on_delete=models.DO_NOTHING,
|
||||
help_text=_('Part category'))
|
||||
|
||||
IPN = models.CharField(max_length=100, blank=True, help_text=_('Internal Part Number'))
|
||||
IPN = models.CharField(max_length=100, blank=True, help_text=_('Internal Part Number'), validators=[validators.validate_part_ipn])
|
||||
|
||||
revision = models.CharField(max_length=100, blank=True, help_text=_('Part revision or version number'))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user