comparison roundup/hyperdb.py @ 156:9c5ddad06430

get() now has a default arg - for migration only.
author Richard Jones <richard@users.sourceforge.net>
date Mon, 30 Jul 2001 02:38:31 +0000
parents 204f99944de0
children c580555a6508
comparison
equal deleted inserted replaced
155:03bdef2d645b 156:9c5ddad06430
1 # $Id: hyperdb.py,v 1.9 2001-07-29 09:28:23 richard Exp $ 1 # $Id: hyperdb.py,v 1.10 2001-07-30 02:38:31 richard Exp $
2 2
3 # standard python modules 3 # standard python modules
4 import cPickle, re, string 4 import cPickle, re, string
5 5
6 # roundup modules 6 # roundup modules
56 class Database: 56 class Database:
57 # flag to set on retired entries 57 # flag to set on retired entries
58 RETIRED_FLAG = '__hyperdb_retired' 58 RETIRED_FLAG = '__hyperdb_retired'
59 59
60 60
61 _marker = []
61 # 62 #
62 # The base Class class 63 # The base Class class
63 # 64 #
64 class Class: 65 class Class:
65 """The handle to a particular class of nodes in a hyperdatabase.""" 66 """The handle to a particular class of nodes in a hyperdatabase."""
190 # done 191 # done
191 self.db.addnode(self.classname, newid, propvalues) 192 self.db.addnode(self.classname, newid, propvalues)
192 self.db.addjournal(self.classname, newid, 'create', propvalues) 193 self.db.addjournal(self.classname, newid, 'create', propvalues)
193 return newid 194 return newid
194 195
195 def get(self, nodeid, propname): 196 def get(self, nodeid, propname, default=_marker):
196 """Get the value of a property on an existing node of this class. 197 """Get the value of a property on an existing node of this class.
197 198
198 'nodeid' must be the id of an existing node of this class or an 199 'nodeid' must be the id of an existing node of this class or an
199 IndexError is raised. 'propname' must be the name of a property 200 IndexError is raised. 'propname' must be the name of a property
200 of this class or a KeyError is raised. 201 of this class or a KeyError is raised.
201 """ 202 """
202 if propname == 'id': 203 if propname == 'id':
203 return nodeid 204 return nodeid
204 # nodeid = str(nodeid) 205 # nodeid = str(nodeid)
205 d = self.db.getnode(self.classname, nodeid) 206 d = self.db.getnode(self.classname, nodeid)
207 if not d.has_key(propname) and default is not _marker:
208 return default
206 return d[propname] 209 return d[propname]
207 210
208 # XXX not in spec 211 # XXX not in spec
209 def getnode(self, nodeid): 212 def getnode(self, nodeid):
210 ''' Return a convenience wrapper for the node 213 ''' Return a convenience wrapper for the node
788 cl.create(name=option[i], order=i) 791 cl.create(name=option[i], order=i)
789 return hyperdb.Link(name) 792 return hyperdb.Link(name)
790 793
791 # 794 #
792 # $Log: not supported by cvs2svn $ 795 # $Log: not supported by cvs2svn $
796 # Revision 1.9 2001/07/29 09:28:23 richard
797 # Fixed sorting by clicking on column headings.
798 #
793 # Revision 1.8 2001/07/29 08:27:40 richard 799 # Revision 1.8 2001/07/29 08:27:40 richard
794 # Fixed handling of passed-in values in form elements (ie. during a 800 # Fixed handling of passed-in values in form elements (ie. during a
795 # drill-down) 801 # drill-down)
796 # 802 #
797 # Revision 1.7 2001/07/29 07:01:39 richard 803 # Revision 1.7 2001/07/29 07:01:39 richard

Roundup Issue Tracker: http://roundup-tracker.org/