From c4bcc55baee3d84bfe452a4eda9b60c403836f7c Mon Sep 17 00:00:00 2001 From: Helmut Merz Date: Sun, 4 Dec 2011 11:23:51 +0100 Subject: [PATCH] provide common definitions for tracking storage (tracks, records) adapters --- common.py | 38 ++++++++++++++++++++++++++++++++++++++ interfaces.py | 27 ++++++++++++++++++++++++++- 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/common.py b/common.py index 293885c..c16eeda 100644 --- a/common.py +++ b/common.py @@ -33,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 @@ -492,6 +494,42 @@ class ParentRelation(object): rs.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): diff --git a/interfaces.py b/interfaces.py index b4ec500..36c5050 100644 --- a/interfaces.py +++ b/interfaces.py @@ -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):