diff options
author | Benjamin Saller <bcsaller@objectrealms.net> | 2007-07-16 22:47:36 (GMT) |
---|---|---|
committer | Benjamin Saller <bcsaller@objectrealms.net> | 2007-07-16 22:47:36 (GMT) |
commit | d26583e7d16cc3d91dfd58f8dced8969a5425d64 (patch) | |
tree | a76dcb501ca64b6eb7912505501774e1fd402229 /src/olpc/datastore/model.py | |
parent | d750a77ffeb6da5ecd61824f7a8653b0c0ba68e9 (diff) |
relax model restriction by defaulting new keys as strings or recording their types
Diffstat (limited to 'src/olpc/datastore/model.py')
-rw-r--r-- | src/olpc/datastore/model.py | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/src/olpc/datastore/model.py b/src/olpc/datastore/model.py index fbad65f..b6e0829 100644 --- a/src/olpc/datastore/model.py +++ b/src/olpc/datastore/model.py @@ -108,19 +108,31 @@ class Model(object): m.fieldnames = self.fieldnames[:] return m - def fromstring(self, key, value): + def fromstring(self, key, value, allowAddition=False): """create a property from the key name by looking it up in the model.""" kind = None if ':' in key: key, kind = key.split(':', 1) - - mkind = self.fields[key][1] + added = False + field = self.fields.get(key) + if field: mkind = field[1] + elif allowAddition: + # create a new field, this will force a change in the + # model + # and in turn should add a new field action + if not kind: kind = "string" + self.addField(key,kind) + mkind = kind + added = True + else: + raise KeyError("no field specification for %s" % key) + if kind and mkind: if kind != mkind: raise ValueError("""Specified wire encoding for property %s was %s, expected %s""" %(key, kind, mkind)) kind = mkind - return Property(key, value, kind) + return Property(key, value, kind), added def addField(self, key, kind, overrides=None): |