fixed a couple field types being wrong, improved validation, auto-truncate over-length fields

This commit is contained in:
Binh 2011-11-05 14:11:37 -05:00
parent 076efd4036
commit a3f89e3790
2 changed files with 6 additions and 6 deletions

View file

@ -61,7 +61,7 @@ class TextField(Field):
value = self.value or "" value = self.value or ""
if self.uppercase: if self.uppercase:
value = value.upper() 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): class StateField(TextField):
@ -74,7 +74,7 @@ class StateField(TextField):
if value.strip() and self.use_numeric: if value.strip() and self.use_numeric:
return str(enums.state_postal_numeric[value.upper()]).zfill(self.max_length) return str(enums.state_postal_numeric[value.upper()]).zfill(self.max_length)
else: else:
return value.ljust(self.max_length).encode('ascii') return value.ljust(self.max_length).encode('ascii')[:self.max_length]
def validate(self): def validate(self):
super(StateField, self).validate() super(StateField, self).validate()
@ -105,7 +105,7 @@ class NumericField(TextField):
def get_data(self): def get_data(self):
value = self.value or "" 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): def parse(self, s):
self.value = int(s) self.value = int(s)
@ -153,7 +153,7 @@ class MoneyField(Field):
raise ValidationError("value is too long", field=self) raise ValidationError("value is too long", field=self)
def get_data(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): def parse(self, s):
self.value = decimal.Decimal(s) * decimal.Decimal('0.01') self.value = decimal.Decimal(s) * decimal.Decimal('0.01')

View file

@ -83,7 +83,7 @@ class EmployerRecord(model.Model):
required = True required = True
tax_year = NumericField(max_length=4) tax_year = NumericField(max_length=4)
agent_indicator = NumericField(max_length=1, required=False) agent_indicator = TextField(max_length=1, required=False)
employer_ein = TextField(max_length=9) employer_ein = TextField(max_length=9)
agent_for_ein = TextField(max_length=9, required=False) agent_for_ein = TextField(max_length=9, required=False)
terminating_business_indicator = BooleanField() terminating_business_indicator = BooleanField()
@ -276,7 +276,7 @@ class TotalRecord(model.Model):
record_identifier = 'RT' record_identifier = 'RT'
required = True required = True
number_of_rw_records = MoneyField(max_length=7) number_of_rw_records = NumericField(max_length=7)
wages_tips = MoneyField(max_length=15) wages_tips = MoneyField(max_length=15)
federal_income_tax_withheld = MoneyField(max_length=15) federal_income_tax_withheld = MoneyField(max_length=15)
social_security_wages = MoneyField(max_length=15) social_security_wages = MoneyField(max_length=15)