Added record validation functions for everything (that we saw in the PDF),
we should go over them once more to make sure we didn't miss anything, but testing validation should probably be done after that. Verify that the record ordering enforcement code is correct, then start thinking of how to get data from external sources into the record generator.
This commit is contained in:
parent
7dcbd6305b
commit
0646bf7b9b
3 changed files with 111 additions and 11 deletions
|
@ -1,6 +1,6 @@
|
|||
import decimal, datetime
|
||||
import inspect
|
||||
from enums import STATE_POSTAL_NUMERIC
|
||||
import enums
|
||||
|
||||
class ValidationError(Exception):
|
||||
def __init__(self, msg, field=None):
|
||||
|
@ -71,18 +71,18 @@ class StateField(TextField):
|
|||
def get_data(self):
|
||||
value = self.value or ""
|
||||
if value.strip() and self.use_numeric:
|
||||
return str(STATE_POSTAL_NUMERIC[value.upper()]).zfill(self.max_length)
|
||||
return str(enums.state_postal_numeric[value.upper()]).zfill(self.max_length)
|
||||
else:
|
||||
return value.ljust(self.max_length).encode('ascii')
|
||||
|
||||
def validate(self):
|
||||
super(StateField, self).validate()
|
||||
if self.value and self.value.upper() not in STATE_POSTAL_NUMERIC.keys():
|
||||
if self.value and self.value.upper() not in enums.state_postal_numeric.keys():
|
||||
raise ValidationError("%s is not a valid state abbreviation" % self.value, field=self)
|
||||
|
||||
def parse(self, s):
|
||||
if s.strip() and self.use_numeric:
|
||||
states = dict( [(v,k) for (k,v) in STATE_POSTAL_NUMERIC.items()] )
|
||||
states = dict( [(v,k) for (k,v) in enums.state_postal_numeric.items()] )
|
||||
self.value = states[int(s)]
|
||||
else:
|
||||
self.value = s
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue