Skip to content

Commit c36a5df

Browse files
author
Richard Jones
committed
get() now has a default arg - for migration only.
1 parent 21a5381 commit c36a5df

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

roundup/hyperdb.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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 $
22

33
# standard python modules
44
import cPickle, re, string
@@ -58,6 +58,7 @@ class Database:
5858
RETIRED_FLAG = '__hyperdb_retired'
5959

6060

61+
_marker = []
6162
#
6263
# The base Class class
6364
#
@@ -192,7 +193,7 @@ def create(self, **propvalues):
192193
self.db.addjournal(self.classname, newid, 'create', propvalues)
193194
return newid
194195

195-
def get(self, nodeid, propname):
196+
def get(self, nodeid, propname, default=_marker):
196197
"""Get the value of a property on an existing node of this class.
197198
198199
'nodeid' must be the id of an existing node of this class or an
@@ -203,6 +204,8 @@ def get(self, nodeid, propname):
203204
return nodeid
204205
# nodeid = str(nodeid)
205206
d = self.db.getnode(self.classname, nodeid)
207+
if not d.has_key(propname) and default is not _marker:
208+
return default
206209
return d[propname]
207210

208211
# XXX not in spec
@@ -790,6 +793,9 @@ def Choice(name, *options):
790793

791794
#
792795
# $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+
#
793799
# Revision 1.8 2001/07/29 08:27:40 richard
794800
# Fixed handling of passed-in values in form elements (ie. during a
795801
# drill-down)

roundup/roundupdb.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: roundupdb.py,v 1.6 2001-07-30 00:05:54 richard Exp $
1+
# $Id: roundupdb.py,v 1.7 2001-07-30 02:38:31 richard Exp $
22

33
import re, os, smtplib, socket
44

@@ -27,6 +27,7 @@ def uidFromAddress(self, address):
2727
return self.user.create(username=address, address=address,
2828
realname=realname)
2929

30+
_marker = []
3031
# XXX: added the 'creator' faked attribute
3132
class Class(hyperdb.Class):
3233
# Overridden methods:
@@ -71,9 +72,9 @@ def retire(self, nodeid):
7172
for react in self.reactors['retire']:
7273
react(self.db, self, nodeid, None)
7374

74-
def get(self, nodeid, propname):
75+
def get(self, nodeid, propname, default=_marker):
7576
"""Attempts to get the "creation" or "activity" properties should
76-
do the right thing
77+
do the right thing.
7778
"""
7879
if propname == 'creation':
7980
journal = self.db.getjournal(self.classname, nodeid)
@@ -96,7 +97,10 @@ def get(self, nodeid, propname):
9697
else:
9798
return None
9899
return self.db.user.lookup(name)
99-
return hyperdb.Class.get(self, nodeid, propname)
100+
if default is not _marker:
101+
return hyperdb.Class.get(self, nodeid, propname, default)
102+
else:
103+
return hyperdb.Class.get(self, nodeid, propname)
100104

101105
def getprops(self):
102106
"""In addition to the actual properties on the node, these
@@ -145,12 +149,15 @@ def getcontent(self, classname, nodeid):
145149
'''
146150
return open(self.filename(classname, nodeid), 'rb').read()
147151

148-
def get(self, nodeid, propname):
152+
def get(self, nodeid, propname, default=_marker):
149153
''' trap the content propname and get it from the file
150154
'''
151155
if propname == 'content':
152156
return self.getcontent(self.classname, nodeid)
153-
return Class.get(self, nodeid, propname)
157+
if default is not _marker:
158+
return Class.get(self, nodeid, propname, default)
159+
else:
160+
return Class.get(self, nodeid, propname)
154161

155162
def getprops(self):
156163
''' In addition to the actual properties on the node, these methods
@@ -247,6 +254,10 @@ def sendmessage(self, nodeid, msgid):
247254

248255
#
249256
# $Log: not supported by cvs2svn $
257+
# Revision 1.6 2001/07/30 00:05:54 richard
258+
# Fixed IssueClass so that superseders links to its classname rather than
259+
# hard-coded to "issue".
260+
#
250261
# Revision 1.5 2001/07/29 07:01:39 richard
251262
# Added vim command to all source so that we don't get no steenkin' tabs :)
252263
#

0 commit comments

Comments
 (0)