provide common definitions for tracking storage (tracks, records) adapters

This commit is contained in:
Helmut Merz 2011-12-04 11:30:51 +01:00
parent 2c7e2f0e5b
commit a8aa186214
2 changed files with 64 additions and 3 deletions

View file

@ -18,8 +18,6 @@
"""
Common stuff.
$Id$
"""
from zope import component
@ -35,9 +33,11 @@ from zope.security.proxy import isinstance
from zope.traversing.api import getName
from cybertools.storage.interfaces import IStorageInfo
from cybertools.tracking.interfaces import ITrackingStorage
from cybertools.typology.interfaces import IType
from loops.interfaces import ILoopsObject, ILoopsContained
from loops.interfaces import IConcept, IResource, IResourceAdapter
from loops.interfaces import ITracks
from loops import util
@ -488,6 +488,42 @@ class ParentRelation(object):
s.add(value) # how to supply additional parameters?
# records/tracks
class Tracks(object):
""" A tracking storage adapter managing tracks/records.
"""
implements(ITracks)
adapts(ITrackingStorage)
def __init__(self, context):
self.context = context
def __getitem__(self, key):
return self.context[key]
def __iter__(self):
return iter(self.context.values())
def query(self, **criteria):
if 'task' in criteria:
criteria['taskId'] = criteria.pop('task')
if 'party' in criteria:
criteria['userName'] = criteria.pop('party')
if 'run' in criteria:
criteria['runId'] = criteria.pop('run')
return self.context.query(**criteria)
def add(self, task, userName, run=0, **kw):
if not run:
run = self.context.startRun()
trackId = self.context.saveUserTrack(task, run, userName, {})
track = self[trackId]
track.setData(**kw)
return track
# caching (TBD)
def cached(obj):

View file

@ -558,12 +558,37 @@ class INodeContained(Interface):
containers(INode, IViewManager)
# record manager interfaces
# record manager and records/tracks interfaces
class IRecordManager(ILoopsObject):
contains(ITrackingStorage)
class ITracks(Interface):
""" A manager/container of tracks/records.
Usually implemented as an ITrackingStorage adapter.
"""
def __getitem__(key):
""" Return the work item identified by the key given.
"""
def __iter__():
""" Return an iterator of all work items.
"""
def query(**criteria):
""" Search for tracks. Possible criteria are: task, party, run,
timeFrom, timeTo.
"""
def add(task, party, run=0, **kw):
""" Create and register a work item; return it. Additional properties
may be specified via keyword arguments.
"""
# the loops top-level container
class ILoops(ILoopsObject):