Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBenjamin Saller <bcsaller@objectrealms.net>2007-07-16 22:47:36 (GMT)
committer Benjamin Saller <bcsaller@objectrealms.net>2007-07-16 22:47:36 (GMT)
commitd26583e7d16cc3d91dfd58f8dced8969a5425d64 (patch)
treea76dcb501ca64b6eb7912505501774e1fd402229 /src
parentd750a77ffeb6da5ecd61824f7a8653b0c0ba68e9 (diff)
relax model restriction by defaulting new keys as strings or recording their types
Diffstat (limited to 'src')
-rw-r--r--src/olpc/datastore/model.py20
-rw-r--r--src/olpc/datastore/xapianindex.py7
2 files changed, 21 insertions, 6 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):
diff --git a/src/olpc/datastore/xapianindex.py b/src/olpc/datastore/xapianindex.py
index 7effc4c..49448d7 100644
--- a/src/olpc/datastore/xapianindex.py
+++ b/src/olpc/datastore/xapianindex.py
@@ -236,7 +236,9 @@ class IndexManager(object):
"""
d = {}
for k,v in props.iteritems():
- p = self.datamodel.fromstring(k, v)
+ p, added = self.datamodel.fromstring(k, v,
+ allowAddition=True)
+ if added is True: self.fields.add(p.key)
d[p.key] = p
return d
@@ -245,6 +247,7 @@ class IndexManager(object):
Props must contain the following:
key -> Property()
"""
+ operation = UPDATE
#
# Version handling
#
@@ -265,7 +268,7 @@ class IndexManager(object):
doc = secore.UnprocessedDocument()
add = doc.fields.append
fp = None
- operation = UPDATE
+
filestuff = None
if filename: