Added load/dump methods which work similarly to those found in
simplejson. Tests seem to work so far. Still need to figure out how to get data into the records in some easy way.
This commit is contained in:
parent
a32feb79ed
commit
068f1bbae4
4 changed files with 118 additions and 34 deletions
16
model.py
16
model.py
|
@ -1,6 +1,8 @@
|
|||
from fields import Field, TextField, MoneyField, StateField
|
||||
from fields import Field
|
||||
|
||||
class Model(object):
|
||||
record_identifier = ' '
|
||||
|
||||
class Model(object):
|
||||
def __init__(self):
|
||||
for (key, value) in self.__class__.__dict__.items():
|
||||
if isinstance(value, Field):
|
||||
|
@ -32,12 +34,10 @@ class Model(object):
|
|||
f.validate()
|
||||
|
||||
def output(self):
|
||||
return ''.join([field.get_data() for field in self.get_sorted_fields()])
|
||||
return ''.join([self.record_identifier] + [field.get_data() for field in self.get_sorted_fields()])
|
||||
|
||||
def read(self, fp):
|
||||
for field in self.get_sorted_fields():
|
||||
field.read(fp)
|
||||
|
||||
|
||||
class TestModel(Model):
|
||||
field_a = TextField(max_length=20)
|
||||
field_b = MoneyField(max_length=10)
|
||||
state = StateField()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue