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:
Binh 2011-10-25 14:54:22 -05:00
parent 775d3d3700
commit 4023d46b4a
4 changed files with 35 additions and 18 deletions

View file

@ -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():