[Zope3-checkins] CVS: Products3/bugtracker - exportimport.py:1.3 tracker.py:1.5
Stephan Richter
srichter@cosmos.phy.tufts.edu
Mon, 28 Jul 2003 07:50:07 -0400
Update of /cvs-repository/Products3/bugtracker
In directory cvs.zope.org:/tmp/cvs-serv23146
Modified Files:
exportimport.py tracker.py
Log Message:
I finally got sick of using Folder as the base and implemented IContainer
myself and I think the result is good. I am now always using integers as
ids and they are always generted for you.
=== Products3/bugtracker/exportimport.py 1.2 => 1.3 ===
--- Products3/bugtracker/exportimport.py:1.2 Sat Jul 26 18:14:15 2003
+++ Products3/bugtracker/exportimport.py Mon Jul 28 07:49:31 2003
@@ -257,7 +257,7 @@
self.bug_name = attrs.get('id')
def endBug(self):
- self.context.setObject(self.bug_name, self.bug)
+ self.context.setObject(self.bug_name, self.bug, True)
def startDescription(self, attrs):
self.chars = u''
=== Products3/bugtracker/tracker.py 1.4 => 1.5 ===
--- Products3/bugtracker/tracker.py:1.4 Mon Jul 28 06:21:06 2003
+++ Products3/bugtracker/tracker.py Mon Jul 28 07:49:31 2003
@@ -15,47 +15,93 @@
$Id$
"""
+from persistence import Persistent
+from zodb.btrees.IOBTree import IOBTree
from zope.app.content.folder import Folder
from zope.app.interfaces.dublincore import IZopeDublinCore
+from zope.app.services.servicecontainer import ServiceManagerContainer
from zope.component import queryAdapter
from zope.interface import implements
from zopeproducts.bugtracker.interfaces import IBugTracker
-class BugTracker(Folder):
+class BugTracker(Persistent, ServiceManagerContainer):
implements(IBugTracker)
+ def __init__(self):
+ self.data = IOBTree()
+
def setTitle(self, title):
- """Set bug tracker title."""
+ """See zopeproducts.bugtracker.interfaces.IBugTracker"""
dc = queryAdapter(self, IZopeDublinCore)
dc.title = title
def getTitle(self):
- """Get bug tracker title."""
+ """See zopeproducts.bugtracker.interfaces.IBugTracker"""
dc = queryAdapter(self, IZopeDublinCore)
return dc.title
# See zopeproducts.bugtracker.interfaces.IBugTracker
title = property(getTitle, setTitle)
- def items(self):
- items = list(super(BugTracker, self).items())
- items.sort(compare)
- return items
-
- def setObject(self, name, object):
- if not self.keys():
- name = '1'
- else:
- int_names = map(lambda name: int(name), self.keys())
- name = str(max(int_names)+1)
- return super(BugTracker, self).setObject(name, object)
+ # IContainer API methods
+
+ def keys(self):
+ """See zope.interface.common.mapping.IEnumerableMapping"""
+ return self.data.keys()
+
+ def __iter__(self):
+ """See zope.interface.common.mapping.IEnumerableMapping"""
+ return iter(self.data.keys())
+
+ def values(self):
+ """See zope.interface.common.mapping.IEnumerableMapping"""
+ return self.data.values()
+ def items(self):
+ """See zope.interface.common.mapping.IEnumerableMapping"""
+ return self.data.items()
-def compare(obj1, obj2):
- try:
- return cmp(int(obj1[0]), int(obj2[0]))
- except ValueError:
- return cmp(obj1[0], obj2[0])
+ def __len__(self):
+ """See zope.interface.common.mapping.IEnumerableMapping"""
+ return len(self.data)
+
+ def __getitem__(self, name):
+ """See zope.interface.common.mapping.ItemMapping"""
+ name = int(name)
+ return self.data[name]
+
+ def get(self, name, default=None):
+ """See zope.interface.common.mapping.IReadMapping"""
+ try:
+ name = int(name)
+ return self.data.get(name, default)
+ except ValueError:
+ return default
+
+ def __contains__(self, name):
+ """See zope.interface.common.mapping.IReadMapping"""
+ name = int(name)
+ return self.data.has_key(name)
+
+ def setObject(self, name, object, forceName=False):
+ """Add the given object to the folder under the given name."""
+ # It is sometimes necessary to force in a name, since bugs might refer
+ # to each other. This is particualry important when importing XML
+ # data.
+ if forceName == False:
+ name = max(list(self.keys())+[0])+1
+ else:
+ name = int(name)
+ if name in self:
+ raise ValueError, 'Name (%i) already in Bug Tracker.' %name
+ self.data[name] = object
+ return name
+
+ def __delitem__(self, name):
+ """Delete the named object from the folder. Raises a KeyError
+ if the object is not found."""
+ name = int(name)
+ del self.data[name]