Changed a few fields to be optional.
Found a fairly difficult bug involved with Field instances being shared across Records. The issue is that Field instances are static. I either need to implement a way to instantiate copies of all the Fields per-record, or write a wrapping interface which provides a unique value store on a per-Record basis.
This commit is contained in:
parent
775d3d3700
commit
4023d46b4a
4 changed files with 35 additions and 18 deletions
|
@ -13,6 +13,7 @@ class ValidationError(Exception):
|
||||||
else:
|
else:
|
||||||
return repr(self.msg)
|
return repr(self.msg)
|
||||||
|
|
||||||
|
|
||||||
class Field(object):
|
class Field(object):
|
||||||
creation_counter = 0
|
creation_counter = 0
|
||||||
|
|
||||||
|
@ -49,6 +50,12 @@ class Field(object):
|
||||||
self.value = s.strip()
|
self.value = s.strip()
|
||||||
|
|
||||||
|
|
||||||
|
class FieldInterface(object):
|
||||||
|
def __init__(self, value_dict, field):
|
||||||
|
self.value_dict = value_dict
|
||||||
|
self.field = field
|
||||||
|
|
||||||
|
|
||||||
class TextField(Field):
|
class TextField(Field):
|
||||||
def validate(self):
|
def validate(self):
|
||||||
if self.value == None and self.required:
|
if self.value == None and self.required:
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
from fields import Field
|
from fields import Field, FieldWrapper
|
||||||
|
|
||||||
class Model(object):
|
class Model(object):
|
||||||
record_identifier = ' '
|
record_identifier = ' '
|
||||||
required = False
|
required = False
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
self.value_dict = {}
|
||||||
|
|
||||||
for (key, value) in self.__class__.__dict__.items():
|
for (key, value) in self.__class__.__dict__.items():
|
||||||
if isinstance(value, Field):
|
if isinstance(value, Field):
|
||||||
field = getattr(self, key)
|
field = getattr(self, key)
|
||||||
|
@ -13,11 +15,19 @@ class Model(object):
|
||||||
setattr(field, 'parent_name', self.__class__.__name__)
|
setattr(field, 'parent_name', self.__class__.__name__)
|
||||||
|
|
||||||
def __setattr__(self, key, value):
|
def __setattr__(self, key, value):
|
||||||
|
print "Model.__setattr__", self, key, value
|
||||||
if hasattr(self, key) and isinstance(getattr(self, key), Field):
|
if hasattr(self, key) and isinstance(getattr(self, key), Field):
|
||||||
getattr(self, key).value = value
|
getattr(self, key).value = value
|
||||||
else:
|
else:
|
||||||
self.__dict__[key] = value
|
self.__dict__[key] = value
|
||||||
|
|
||||||
|
def __getattribute__(self, key):
|
||||||
|
result = object.__getattribute__(self, key)
|
||||||
|
if isinstance(result, Field):
|
||||||
|
return FieldWrapper(self.value_dict, result)
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
def get_fields(self):
|
def get_fields(self):
|
||||||
fields = []
|
fields = []
|
||||||
for key in self.__class__.__dict__.keys():
|
for key in self.__class__.__dict__.keys():
|
||||||
|
|
|
@ -163,23 +163,23 @@ class EmployeeWageRecord(model.Model):
|
||||||
medicare_tax_withheld = MoneyField(max_length=11)
|
medicare_tax_withheld = MoneyField(max_length=11)
|
||||||
social_security_tips = MoneyField(max_length=11)
|
social_security_tips = MoneyField(max_length=11)
|
||||||
advance_eic = MoneyField(max_length=11)
|
advance_eic = MoneyField(max_length=11)
|
||||||
dependent_care_benefits = MoneyField(max_length=11)
|
dependent_care_benefits = MoneyField(max_length=11, required=False)
|
||||||
deferred_compensation_401k = MoneyField(max_length=11)
|
deferred_compensation_401k = MoneyField(max_length=11, required=False)
|
||||||
deferred_compensation_403b = MoneyField(max_length=11)
|
deferred_compensation_403b = MoneyField(max_length=11, required=False)
|
||||||
deferred_compensation_408k = MoneyField(max_length=11)
|
deferred_compensation_408k = MoneyField(max_length=11, required=False)
|
||||||
deferred_compensation_457b = MoneyField(max_length=11)
|
deferred_compensation_457b = MoneyField(max_length=11, required=False)
|
||||||
deferred_compensation_501c = MoneyField(max_length=11)
|
deferred_compensation_501c = MoneyField(max_length=11, required=False)
|
||||||
military_pay = MoneyField(max_length=11)
|
military_pay = MoneyField(max_length=11, required=False)
|
||||||
non_qualified_457 = MoneyField(max_length=11)
|
non_qualified_457 = MoneyField(max_length=11, required=False)
|
||||||
employer_contrib_to_hsa = MoneyField(max_length=11)
|
employer_contrib_to_hsa = MoneyField(max_length=11, required=False)
|
||||||
non_qualified_not_457 = MoneyField(max_length=11)
|
non_qualified_not_457 = MoneyField(max_length=11, required=False)
|
||||||
nontaxable_combat_pay = MoneyField(max_length=11)
|
nontaxable_combat_pay = MoneyField(max_length=11, required=False)
|
||||||
blank2 = BlankField(max_length=11)
|
blank2 = BlankField(max_length=11)
|
||||||
cost_of_premiums_for_insurance = MoneyField(max_length=11)
|
cost_of_premiums_for_insurance = MoneyField(max_length=11, required=False)
|
||||||
income_nonstatutory_stock_opts = MoneyField(max_length=11)
|
income_nonstatutory_stock_opts = MoneyField(max_length=11, required=False)
|
||||||
deferred_compensation_409a = MoneyField(max_length=11)
|
deferred_compensation_409a = MoneyField(max_length=11, required=False)
|
||||||
designated_roth_contrib_401k = MoneyField(max_length=11)
|
designated_roth_contrib_401k = MoneyField(max_length=11, required=False)
|
||||||
designated_roth_contrib_403b = MoneyField(max_length=11)
|
designated_roth_contrib_403b = MoneyField(max_length=11, required=False)
|
||||||
blank3 = BlankField(max_length=23)
|
blank3 = BlankField(max_length=23)
|
||||||
statutory_employee_indicator = BooleanField()
|
statutory_employee_indicator = BooleanField()
|
||||||
blank4 = BlankField(max_length=1)
|
blank4 = BlankField(max_length=1)
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -1,6 +1,6 @@
|
||||||
from distutils.core import setup
|
from distutils.core import setup
|
||||||
setup(name='pyaccuwage',
|
setup(name='pyaccuwage',
|
||||||
version='0.0.3',
|
version='0.0.4',
|
||||||
packages=['pyaccuwage'],
|
packages=['pyaccuwage'],
|
||||||
zip_safe=True,
|
zip_safe=True,
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue