provide common definitions for tracking storage (tracks, records) adapters
This commit is contained in:
		
							parent
							
								
									991e78a1fe
								
							
						
					
					
						commit
						c4bcc55bae
					
				
					 2 changed files with 64 additions and 1 deletions
				
			
		
							
								
								
									
										38
									
								
								common.py
									
										
									
									
									
								
							
							
						
						
									
										38
									
								
								common.py
									
										
									
									
									
								
							| 
						 | 
					@ -33,9 +33,11 @@ from zope.security.proxy import isinstance
 | 
				
			||||||
from zope.traversing.api import getName
 | 
					from zope.traversing.api import getName
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from cybertools.storage.interfaces import IStorageInfo
 | 
					from cybertools.storage.interfaces import IStorageInfo
 | 
				
			||||||
 | 
					from cybertools.tracking.interfaces import ITrackingStorage
 | 
				
			||||||
from cybertools.typology.interfaces import IType
 | 
					from cybertools.typology.interfaces import IType
 | 
				
			||||||
from loops.interfaces import ILoopsObject, ILoopsContained
 | 
					from loops.interfaces import ILoopsObject, ILoopsContained
 | 
				
			||||||
from loops.interfaces import IConcept, IResource, IResourceAdapter
 | 
					from loops.interfaces import IConcept, IResource, IResourceAdapter
 | 
				
			||||||
 | 
					from loops.interfaces import ITracks
 | 
				
			||||||
from loops import util
 | 
					from loops import util
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -492,6 +494,42 @@ class ParentRelation(object):
 | 
				
			||||||
                rs.add(value)    # how to supply additional parameters?
 | 
					                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)
 | 
					# caching (TBD)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def cached(obj):
 | 
					def cached(obj):
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -558,12 +558,37 @@ class INodeContained(Interface):
 | 
				
			||||||
    containers(INode, IViewManager)
 | 
					    containers(INode, IViewManager)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# record manager interfaces
 | 
					# record manager and records/tracks interfaces
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class IRecordManager(ILoopsObject):
 | 
					class IRecordManager(ILoopsObject):
 | 
				
			||||||
    contains(ITrackingStorage)
 | 
					    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
 | 
					# the loops top-level container
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class ILoops(ILoopsObject):
 | 
					class ILoops(ILoopsObject):
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue