work in progress: concepts, relations, ...; folder: use name as value for parent
This commit is contained in:
parent
2382abf129
commit
e2df59247c
6 changed files with 25 additions and 7 deletions
1
scopes/organize/__init__.py
Normal file
1
scopes/organize/__init__.py
Normal file
|
@ -0,0 +1 @@
|
||||||
|
"""package scopes.organize"""
|
|
@ -71,8 +71,10 @@ class Storage(object):
|
||||||
registry = {}
|
registry = {}
|
||||||
|
|
||||||
def registerContainerClass(cls):
|
def registerContainerClass(cls):
|
||||||
# TODO: error on duplicate key
|
prefix = cls.itemFactory.prefix
|
||||||
registry[cls.itemFactory.prefix] = cls
|
if prefix in registry:
|
||||||
|
raise ValueError("prefix '%s' already registered!" % prefix)
|
||||||
|
registry[prefix] = cls
|
||||||
cls.headCols = cols = tuple(f.lower() for f in cls.itemFactory.headFields)
|
cls.headCols = cols = tuple(f.lower() for f in cls.itemFactory.headFields)
|
||||||
if cls.indexes is None:
|
if cls.indexes is None:
|
||||||
cls.indexes = [cols[i:] for i in range(len(cols))]
|
cls.indexes = [cols[i:] for i in range(len(cols))]
|
||||||
|
|
12
scopes/storage/concept.py
Normal file
12
scopes/storage/concept.py
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
# scopes.storage.concept
|
||||||
|
|
||||||
|
"""Abstract base classes for concept map application classes."""
|
||||||
|
|
||||||
|
from scopes.storage.common import registerContainerClass
|
||||||
|
from scopes.storage.tracking import Container, Track
|
||||||
|
|
||||||
|
|
||||||
|
class Concept(Track):
|
||||||
|
|
||||||
|
headFields = ['parent', 'name']
|
||||||
|
|
|
@ -10,23 +10,23 @@ class Folder(Track):
|
||||||
prefix = 'fldr'
|
prefix = 'fldr'
|
||||||
|
|
||||||
def keys(self):
|
def keys(self):
|
||||||
for f in self.container.query(parent=self.uid):
|
for f in self.container.query(parent=self.name):
|
||||||
yield f.name
|
yield f.name
|
||||||
|
|
||||||
def get(self, key, default=None):
|
def get(self, key, default=None):
|
||||||
value = self.container.queryLast(parent=self.uid, name=key)
|
value = self.container.queryLast(parent=self.name, name=key)
|
||||||
if value is None:
|
if value is None:
|
||||||
return default
|
return default
|
||||||
return value
|
return value
|
||||||
|
|
||||||
def __getitem__(self, key):
|
def __getitem__(self, key):
|
||||||
value = self.container.queryLast(parent=self.uid, name=key)
|
value = self.container.queryLast(parent=self.name, name=key)
|
||||||
if value is None:
|
if value is None:
|
||||||
raise KeyError(key)
|
raise KeyError(key)
|
||||||
return value
|
return value
|
||||||
|
|
||||||
def __setitem__(self, key, value):
|
def __setitem__(self, key, value):
|
||||||
value.set('parent', self.uid)
|
value.set('parent', self.name)
|
||||||
value.set('name', key)
|
value.set('name', key)
|
||||||
self.container.save(value)
|
self.container.save(value)
|
||||||
|
|
||||||
|
|
3
scopes/storage/relation.py
Normal file
3
scopes/storage/relation.py
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
# scopes.storage.relation
|
||||||
|
|
||||||
|
"""An SQL-based relationship engine using RDF-like triples."""
|
|
@ -80,7 +80,7 @@ class Test(unittest.TestCase):
|
||||||
top['child1'] = folder.Folder(data=dict(title='First Child'))
|
top['child1'] = folder.Folder(data=dict(title='First Child'))
|
||||||
self.assertEqual(list(top.keys()), ['child1'])
|
self.assertEqual(list(top.keys()), ['child1'])
|
||||||
ch1 = top['child1']
|
ch1 = top['child1']
|
||||||
self.assertEqual(ch1.parent, top.uid)
|
self.assertEqual(ch1.parent, top.name)
|
||||||
assert list(top.keys()) == ['child1']
|
assert list(top.keys()) == ['child1']
|
||||||
|
|
||||||
def suite():
|
def suite():
|
||||||
|
|
Loading…
Add table
Reference in a new issue