mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
fix validation
This commit is contained in:
parent
fc6f1b4acc
commit
b8cdcab10d
@ -72,24 +72,27 @@ class ReferenceIndexingMixin(models.Model):
|
|||||||
|
|
||||||
reference = getattr(self, 'reference', '')
|
reference = getattr(self, 'reference', '')
|
||||||
|
|
||||||
# Default value if we cannot convert to an integer
|
self.reference_int = extract_int(reference)
|
||||||
ref_int = 0
|
|
||||||
|
|
||||||
# Look at the start of the string - can it be "integerized"?
|
|
||||||
result = re.match(r"^(\d+)", reference)
|
|
||||||
|
|
||||||
if result and len(result.groups()) == 1:
|
|
||||||
ref = result.groups()[0]
|
|
||||||
try:
|
|
||||||
ref_int = int(ref)
|
|
||||||
except:
|
|
||||||
ref_int = 0
|
|
||||||
|
|
||||||
self.reference_int = ref_int
|
|
||||||
|
|
||||||
reference_int = models.BigIntegerField(default=0)
|
reference_int = models.BigIntegerField(default=0)
|
||||||
|
|
||||||
|
|
||||||
|
def extract_int(reference):
|
||||||
|
# Default value if we cannot convert to an integer
|
||||||
|
ref_int = 0
|
||||||
|
|
||||||
|
# Look at the start of the string - can it be "integerized"?
|
||||||
|
result = re.match(r"^(\d+)", reference)
|
||||||
|
|
||||||
|
if result and len(result.groups()) == 1:
|
||||||
|
ref = result.groups()[0]
|
||||||
|
try:
|
||||||
|
ref_int = int(ref)
|
||||||
|
except:
|
||||||
|
ref_int = 0
|
||||||
|
return ref_int
|
||||||
|
|
||||||
|
|
||||||
class InvenTreeAttachment(models.Model):
|
class InvenTreeAttachment(models.Model):
|
||||||
""" Provides an abstracted class for managing file attachments.
|
""" Provides an abstracted class for managing file attachments.
|
||||||
|
|
||||||
|
@ -28,6 +28,8 @@ from rest_framework.fields import empty
|
|||||||
from rest_framework.exceptions import ValidationError
|
from rest_framework.exceptions import ValidationError
|
||||||
from rest_framework.serializers import DecimalField
|
from rest_framework.serializers import DecimalField
|
||||||
|
|
||||||
|
from .models import extract_int
|
||||||
|
|
||||||
|
|
||||||
class InvenTreeMoneySerializer(MoneyField):
|
class InvenTreeMoneySerializer(MoneyField):
|
||||||
"""
|
"""
|
||||||
@ -246,9 +248,9 @@ class ReferenceIndexingSerializerMixin():
|
|||||||
for the BigIntegerField
|
for the BigIntegerField
|
||||||
"""
|
"""
|
||||||
def validate_reference(self, value):
|
def validate_reference(self, value):
|
||||||
if int(value) < -models.BigIntegerField.MAX_BIGINT:
|
if extract_int(value) < -models.BigIntegerField.MAX_BIGINT:
|
||||||
raise serializers.ValidationError('reference is to to small')
|
raise serializers.ValidationError('reference is to to small')
|
||||||
if int(value) > models.BigIntegerField.MAX_BIGINT:
|
if extract_int(value) > models.BigIntegerField.MAX_BIGINT:
|
||||||
raise serializers.ValidationError('reference is to to big')
|
raise serializers.ValidationError('reference is to to big')
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user