folder: use rid for parent; more on concept / organize
This commit is contained in:
parent
e2df59247c
commit
83071842c8
6 changed files with 35 additions and 6 deletions
13
scopes/organize/task.py
Normal file
13
scopes/organize/task.py
Normal file
|
@ -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'
|
||||
|
|
@ -8,5 +8,5 @@ from scopes.storage.tracking import Container, Track
|
|||
|
||||
class Concept(Track):
|
||||
|
||||
headFields = ['parent', 'name']
|
||||
headFields = ['name']
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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'
|
||||
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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():
|
||||
|
|
Loading…
Add table
Reference in a new issue