basic implementation for subtask assignment working again (with the cybertools.relation package)

git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@669 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
helmutm 2005-11-09 11:22:46 +00:00
parent 81d54dab91
commit b7a0b9d836
4 changed files with 64 additions and 76 deletions

View file

@ -1,6 +1,12 @@
# $Id$
loops - Linked Objects for Organizational Process Services
==========================================================
Task Examples::
($Id$)
Tasks and Subtasks
~~~~~~~~~~~~~~~~~~
Let's start with creating a few example tasks:
>>> from loops.task import Task
>>> t1 = Task()
@ -11,3 +17,36 @@ Task Examples::
>>> t2.title
u'Second Task'
Now we want to make the second task a subtask of the first one.
In order to do this we first have to provide a relations registry. For
testing we use a simple dummy implementation.
>>> from cybertools.relation.interfaces import IRelationsRegistry
>>> from cybertools.relation.registry import DummyRelationsRegistry
>>> from zope.app.testing import ztapi
>>> ztapi.provideUtility(IRelationsRegistry, DummyRelationsRegistry())
Now we can assign the task t2 as a subtask to t1:
>>> t1.assignSubtask(t2)
We can now ask our tasks for their subtasks and parent tasks:
>>> st1 = t1.getSubtasks()
>>> len(st1)
1
>>> t2 in st1
True
>>> len(t1.getParentTasks())
0
>>> pt2 = t2.getParentTasks()
>>> len(pt2)
1
>>> t1 in pt2
True
>>> len(t2.getSubtasks())
0

View file

@ -1,47 +0,0 @@
#
# Copyright (c) 2004 Helmut Merz helmutm@cy55.de
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
"""
relation classes implementation.
$Id$
"""
from BTrees.OOBTree import OOSet
from zope.interface import implements
from zope.app import zapi
from interfaces import IRelation, IRelations
class Relation(object):
implements(IRelation)
def __init__(self, source, target):
self._source = source
self._target = target
class Relations(OOSet):
implements(IRelations)
def add(self, relation, **kw):
self.insert(relation)

33
task.py
View file

@ -27,14 +27,24 @@ from zope.app.container.ordered import OrderedContainer
from zope.app.copypastemove import ObjectCopier
from zope.app import zapi
from zope.schema.fieldproperty import FieldProperty
from zope.component.interfaces import IFactory
from relation import Relation, Relations
from cybertools.relation.interfaces import IRelationsRegistry
from cybertools.relation import DyadicRelation
#from relation import Relation, Relations
from resource import Resource
from interfaces import ITask
from copy import copy
class SubtaskRelation(DyadicRelation):
""" Relation of a first task (the parent task) to a second task
(the subtask).
"""
class Task(OrderedContainer):
implements(ITask)
@ -53,19 +63,22 @@ class Task(OrderedContainer):
# subtasks:
def getSubtasks(self, taskTypes=None):
st = [ r._target for r in self._subtasks ]
st.sort(lambda x,y: x.priority < y.priority and -1 or 1)
return tuple(st)
registry = zapi.getUtility(IRelationsRegistry)
return [r.second
for r in registry.query(relationship=SubtaskRelation,
first=self)]
# TODO: sort according to priority
def getParentTasks(self, taskTypes=None):
pt = [ r._source for r in self._parentTasks ]
return tuple(pt)
registry = zapi.getUtility(IRelationsRegistry)
return [r.first
for r in registry.query(relationship=SubtaskRelation,
second=self)]
def assignSubtask(self, task):
if task not in self.getSubtasks():
rel = Relation(self, task)
self._subtasks.add(rel)
task._parentTasks.add(rel)
registry = zapi.getUtility(IRelationsRegistry)
registry.register(SubtaskRelation(self, task))
# TODO (?): avoid duplicates
def createSubtask(self, taskType=None, container=None, name=None):
container = container or zapi.getParent(self)

View file

@ -30,23 +30,6 @@ class TestTask(unittest.TestCase):
# the tests...
def testInterface(self):
self.assert_(ITask.providedBy(Task()),
'Interface ITask is not implemented by class Task.')
self.assert_(IContained.providedBy(Task()),
'Interface IContained is not implemented by class Task.')
verifyClass(ITask, Task)
def testContained(self):
self.assertEqual(u'tsk1', zapi.name(self.t1))
self.assertEqual(u'f1', zapi.name(zapi.getParent(self.t1)))
def testTitle(self):
t = Task()
self.assertEqual(u'', t.title)
t.title = u'First Task'
self.assertEqual(u'First Task', t.title)
def testQualifier(self):
t = Task()
self.assertEqual(u'', t.qualifier)