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
|
@ -12,6 +12,7 @@ class ValidationError(Exception):
|
|||
return "(%s.%s) %s" % (self.field.parent_name, self.field.name, self.msg)
|
||||
else:
|
||||
return repr(self.msg)
|
||||
|
||||
|
||||
class Field(object):
|
||||
creation_counter = 0
|
||||
|
@ -49,6 +50,12 @@ class Field(object):
|
|||
self.value = s.strip()
|
||||
|
||||
|
||||
class FieldInterface(object):
|
||||
def __init__(self, value_dict, field):
|
||||
self.value_dict = value_dict
|
||||
self.field = field
|
||||
|
||||
|
||||
class TextField(Field):
|
||||
def validate(self):
|
||||
if self.value == None and self.required:
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
from fields import Field
|
||||
from fields import Field, FieldWrapper
|
||||
|
||||
class Model(object):
|
||||
record_identifier = ' '
|
||||
required = False
|
||||
|
||||
def __init__(self):
|
||||
self.value_dict = {}
|
||||
|
||||
for (key, value) in self.__class__.__dict__.items():
|
||||
if isinstance(value, Field):
|
||||
field = getattr(self, key)
|
||||
|
@ -13,11 +15,19 @@ class Model(object):
|
|||
setattr(field, 'parent_name', self.__class__.__name__)
|
||||
|
||||
def __setattr__(self, key, value):
|
||||
print "Model.__setattr__", self, key, value
|
||||
if hasattr(self, key) and isinstance(getattr(self, key), Field):
|
||||
getattr(self, key).value = value
|
||||
else:
|
||||
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):
|
||||
fields = []
|
||||
for key in self.__class__.__dict__.keys():
|
||||
|
|
|
@ -163,23 +163,23 @@ class EmployeeWageRecord(model.Model):
|
|||
medicare_tax_withheld = MoneyField(max_length=11)
|
||||
social_security_tips = MoneyField(max_length=11)
|
||||
advance_eic = MoneyField(max_length=11)
|
||||
dependent_care_benefits = MoneyField(max_length=11)
|
||||
deferred_compensation_401k = MoneyField(max_length=11)
|
||||
deferred_compensation_403b = MoneyField(max_length=11)
|
||||
deferred_compensation_408k = MoneyField(max_length=11)
|
||||
deferred_compensation_457b = MoneyField(max_length=11)
|
||||
deferred_compensation_501c = MoneyField(max_length=11)
|
||||
military_pay = MoneyField(max_length=11)
|
||||
non_qualified_457 = MoneyField(max_length=11)
|
||||
employer_contrib_to_hsa = MoneyField(max_length=11)
|
||||
non_qualified_not_457 = MoneyField(max_length=11)
|
||||
nontaxable_combat_pay = MoneyField(max_length=11)
|
||||
dependent_care_benefits = MoneyField(max_length=11, required=False)
|
||||
deferred_compensation_401k = MoneyField(max_length=11, required=False)
|
||||
deferred_compensation_403b = MoneyField(max_length=11, required=False)
|
||||
deferred_compensation_408k = MoneyField(max_length=11, required=False)
|
||||
deferred_compensation_457b = MoneyField(max_length=11, required=False)
|
||||
deferred_compensation_501c = MoneyField(max_length=11, required=False)
|
||||
military_pay = MoneyField(max_length=11, required=False)
|
||||
non_qualified_457 = MoneyField(max_length=11, required=False)
|
||||
employer_contrib_to_hsa = MoneyField(max_length=11, required=False)
|
||||
non_qualified_not_457 = MoneyField(max_length=11, required=False)
|
||||
nontaxable_combat_pay = MoneyField(max_length=11, required=False)
|
||||
blank2 = BlankField(max_length=11)
|
||||
cost_of_premiums_for_insurance = MoneyField(max_length=11)
|
||||
income_nonstatutory_stock_opts = MoneyField(max_length=11)
|
||||
deferred_compensation_409a = MoneyField(max_length=11)
|
||||
designated_roth_contrib_401k = MoneyField(max_length=11)
|
||||
designated_roth_contrib_403b = MoneyField(max_length=11)
|
||||
cost_of_premiums_for_insurance = MoneyField(max_length=11, required=False)
|
||||
income_nonstatutory_stock_opts = MoneyField(max_length=11, required=False)
|
||||
deferred_compensation_409a = MoneyField(max_length=11, required=False)
|
||||
designated_roth_contrib_401k = MoneyField(max_length=11, required=False)
|
||||
designated_roth_contrib_403b = MoneyField(max_length=11, required=False)
|
||||
blank3 = BlankField(max_length=23)
|
||||
statutory_employee_indicator = BooleanField()
|
||||
blank4 = BlankField(max_length=1)
|
||||
|
|
2
setup.py
2
setup.py
|
@ -1,6 +1,6 @@
|
|||
from distutils.core import setup
|
||||
setup(name='pyaccuwage',
|
||||
version='0.0.3',
|
||||
version='0.0.4',
|
||||
packages=['pyaccuwage'],
|
||||
zip_safe=True,
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue