diff --git a/scopes/organize/task.py b/scopes/organize/task.py new file mode 100644 index 0000000..c0a98cc --- /dev/null +++ b/scopes/organize/task.py @@ -0,0 +1,13 @@ +# scopes.organize.task + +"""Task (and corresponding container) implementation.""" + +from scopes.storage.common import registerContainerClass +from scopes.storage.concept import Concept + + +class Task(Concept): + + headFields = ['name'] + prefix = 'tsk' + diff --git a/scopes/storage/concept.py b/scopes/storage/concept.py index 967f3a4..95ede52 100644 --- a/scopes/storage/concept.py +++ b/scopes/storage/concept.py @@ -8,5 +8,5 @@ from scopes.storage.tracking import Container, Track class Concept(Track): - headFields = ['parent', 'name'] + headFields = ['name'] diff --git a/scopes/storage/folder.py b/scopes/storage/folder.py index c5e80d5..9ac89be 100644 --- a/scopes/storage/folder.py +++ b/scopes/storage/folder.py @@ -10,23 +10,23 @@ class Folder(Track): prefix = 'fldr' def keys(self): - for f in self.container.query(parent=self.name): + for f in self.container.query(parent=self.rid): yield f.name def get(self, key, default=None): - value = self.container.queryLast(parent=self.name, name=key) + value = self.container.queryLast(parent=self.rid, name=key) if value is None: return default return value def __getitem__(self, key): - value = self.container.queryLast(parent=self.name, name=key) + value = self.container.queryLast(parent=self.rid, name=key) if value is None: raise KeyError(key) return value def __setitem__(self, key, value): - value.set('parent', self.name) + value.set('parent', self.rid) value.set('name', key) self.container.save(value) diff --git a/scopes/storage/relation.py b/scopes/storage/relation.py index 100528e..2d2bd5a 100644 --- a/scopes/storage/relation.py +++ b/scopes/storage/relation.py @@ -1,3 +1,13 @@ # scopes.storage.relation """An SQL-based relationship engine using RDF-like triples.""" + +from scopes.storage.common import registerContainerClass +from scopes.storage.tracking import Container, Track + + +class Triple(Track): + + headFields = ['first', 'second', 'pred'] + prefix = 'rel' + diff --git a/scopes/storage/tracking.py b/scopes/storage/tracking.py index ba0d5c0..9a8d8f3 100644 --- a/scopes/storage/tracking.py +++ b/scopes/storage/tracking.py @@ -59,6 +59,12 @@ class Track(object): return None return '%s-%d' % (self.prefix, self.trackId) + @property + def rid(self): + if self.trackId is None: + return '' + return str(self.trackId) + @registerContainerClass class Container(object): diff --git a/tests/test_storage.py b/tests/test_storage.py index ab234ad..d61f459 100644 --- a/tests/test_storage.py +++ b/tests/test_storage.py @@ -80,7 +80,7 @@ class Test(unittest.TestCase): top['child1'] = folder.Folder(data=dict(title='First Child')) self.assertEqual(list(top.keys()), ['child1']) ch1 = top['child1'] - self.assertEqual(ch1.parent, top.name) + self.assertEqual(ch1.parent, top.rid) assert list(top.keys()) == ['child1'] def suite():