fixed a couple field types being wrong, improved validation, auto-truncate over-length fields
This commit is contained in:
parent
076efd4036
commit
a3f89e3790
2 changed files with 6 additions and 6 deletions
|
@ -61,7 +61,7 @@ class TextField(Field):
|
|||
value = self.value or ""
|
||||
if self.uppercase:
|
||||
value = value.upper()
|
||||
return value.ljust(self.max_length).encode('ascii')
|
||||
return value.ljust(self.max_length).encode('ascii')[:self.max_length]
|
||||
|
||||
|
||||
class StateField(TextField):
|
||||
|
@ -74,7 +74,7 @@ class StateField(TextField):
|
|||
if value.strip() and self.use_numeric:
|
||||
return str(enums.state_postal_numeric[value.upper()]).zfill(self.max_length)
|
||||
else:
|
||||
return value.ljust(self.max_length).encode('ascii')
|
||||
return value.ljust(self.max_length).encode('ascii')[:self.max_length]
|
||||
|
||||
def validate(self):
|
||||
super(StateField, self).validate()
|
||||
|
@ -105,7 +105,7 @@ class NumericField(TextField):
|
|||
|
||||
def get_data(self):
|
||||
value = self.value or ""
|
||||
return str(value).zfill(self.max_length)
|
||||
return str(value).zfill(self.max_length)[:self.max_length]
|
||||
|
||||
def parse(self, s):
|
||||
self.value = int(s)
|
||||
|
@ -153,7 +153,7 @@ class MoneyField(Field):
|
|||
raise ValidationError("value is too long", field=self)
|
||||
|
||||
def get_data(self):
|
||||
return str(int((self.value or 0)*100)).encode('ascii').zfill(self.max_length)
|
||||
return str(int((self.value or 0)*100)).encode('ascii').zfill(self.max_length)[:self.max_length]
|
||||
|
||||
def parse(self, s):
|
||||
self.value = decimal.Decimal(s) * decimal.Decimal('0.01')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue