summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 8155427)
raw | patch | inline | side by side (parent: 8155427)
author | jlgijsbers <jlgijsbers@57a73879-2fb5-44c3-a270-3262357dd7e2> | |
Sun, 16 Nov 2003 19:59:10 +0000 (19:59 +0000) | ||
committer | jlgijsbers <jlgijsbers@57a73879-2fb5-44c3-a270-3262357dd7e2> | |
Sun, 16 Nov 2003 19:59:10 +0000 (19:59 +0000) |
in roundupdb.
git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@1996 57a73879-2fb5-44c3-a270-3262357dd7e2
git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@1996 57a73879-2fb5-44c3-a270-3262357dd7e2
roundup/hyperdb.py | patch | blob | history | |
roundup/roundupdb.py | patch | blob | history | |
test/db_test_base.py | patch | blob | history |
diff --git a/roundup/hyperdb.py b/roundup/hyperdb.py
index 2933a9989be4464a26014ff5c5e31494dad834fc..26a6c906fcb8edb4c2c1bb207fa5cb9d6ef97958 100644 (file)
--- a/roundup/hyperdb.py
+++ b/roundup/hyperdb.py
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
#
-# $Id: hyperdb.py,v 1.92 2003-11-16 18:41:40 jlgijsbers Exp $
+# $Id: hyperdb.py,v 1.93 2003-11-16 19:59:10 jlgijsbers Exp $
"""
Hyperdatabase implementation, especially field types.
'''
raise NotImplementedError
+ def safeget(self, nodeid, propname, default=None):
+ try:
+ return self.get(nodeid, propname)
+ except (KeyError, IndexError):
+ return default
+
class HyperdbValueError(ValueError):
''' Error converting a raw value into a Hyperdb value '''
pass
diff --git a/roundup/roundupdb.py b/roundup/roundupdb.py
index f69e1fe4d7063efe7ae166690a295600ff9f7a01..60c8fe40276aa17af3753c13c8f0291886b6db32 100644 (file)
--- a/roundup/roundupdb.py
+++ b/roundup/roundupdb.py
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
#
-# $Id: roundupdb.py,v 1.93 2003-11-06 19:01:57 jlgijsbers Exp $
+# $Id: roundupdb.py,v 1.94 2003-11-16 19:59:09 jlgijsbers Exp $
__doc__ = """
Extending hyperdb with types specific to issue-tracking.
If 'msgid' is None, the message gets sent only to the nosy
list, and it's called a 'System Message'.
"""
- authid, recipients = None, []
- if msgid:
- authid = self.db.msg.get(msgid, 'author')
- recipients = self.db.msg.get(msgid, 'recipients')
+ authid = self.db.msg.safeget(msgid, 'author')
+ recipients = self.db.msg.safeget(msgid, 'recipients', [])
sendto = []
seen_message = dict([(recipient, 1) for recipient in recipients])
users = self.db.user
messages = self.db.msg
files = self.db.file
-
- inreplyto, messageid = None, None
- if msgid:
- inreplyto = messages.get(msgid, 'inreplyto')
- messageid = messages.get(msgid, 'messageid')
-
- # make up a messageid if there isn't one (web edit)
- if not messageid:
- # this is an old message that didn't get a messageid, so
- # create one
- messageid = "<%s.%s.%s%s@%s>"%(time.time(), random.random(),
- self.classname, nodeid,
- self.db.config.MAIL_DOMAIN)
- messages.set(msgid, messageid=messageid)
+
+ inreplyto = messages.safeget(msgid, 'inreplyto')
+ messageid = messages.safeget(msgid, 'messageid')
+
+ # make up a messageid if there isn't one (web edit)
+ if not messageid:
+ # this is an old message that didn't get a messageid, so
+ # create one
+ messageid = "<%s.%s.%s%s@%s>"%(time.time(), random.random(),
+ self.classname, nodeid,
+ self.db.config.MAIL_DOMAIN)
+ messages.set(msgid, messageid=messageid)
# send an email to the people who missed out
cn = self.classname
title = self.get(nodeid, 'title') or '%s message copy'%cn
- authid, authname, authaddr = None, '', ''
- if msgid:
- authid = messages.get(msgid, 'author')
- authname = users.get(authid, 'realname')
- if not authname:
- authname = users.get(authid, 'username')
- authaddr = users.get(authid, 'address')
- if authaddr:
- authaddr = " <%s>" % straddr( ('',authaddr) )
- else:
- authaddr = ''
+ authid = messages.safeget(msgid, 'author')
+ authname = users.safeget(authid, 'realname')
+ if not authname:
+ authname = users.safeget(authid, 'username', '')
+ authaddr = users.safeget(authid, 'address', '')
+ if authaddr:
+ authaddr = " <%s>" % straddr( ('',authaddr) )
# make the message body
m = ['']
m.append('')
# add the content
- if msgid:
- m.append(messages.get(msgid, 'content'))
+ m.append(messages.safeget(msgid, 'content', ''))
# add the change note
if note:
diff --git a/test/db_test_base.py b/test/db_test_base.py
index 57d6e2bc02c8a6799376d7058e72efd803fbadaf..2435134a76620c1a22b014bf364e1771e4fe0834 100644 (file)
--- a/test/db_test_base.py
+++ b/test/db_test_base.py
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
#
-# $Id: db_test_base.py,v 1.8 2003-11-14 00:11:19 richard Exp $
+# $Id: db_test_base.py,v 1.9 2003-11-16 19:59:06 jlgijsbers Exp $
import unittest, os, shutil, errno, imp, sys, time, pprint
ae(self.db.user.get('3', 'username'), 'blop')
ae(self.db.issue.get('2', 'title'), 'issue two')
+ def testSafeGet(self):
+ # existent nodeid, existent property
+ self.assertEqual(self.db.user.safeget('1', 'username'), 'admin')
+ # existent nodeid, nonexistent property
+ self.assertEqual(self.db.user.safeget('1', 'nonexistent'), None)
+ # nonexistent nodeid, existent property
+ self.assertEqual(self.db.user.safeget('999', 'username'), None)
+ # nonexistent nodeid, nonexistent property
+ self.assertEqual(self.db.user.safeget('999', 'nonexistent'), None)
+ # different default
+ self.assertEqual(self.db.issue.safeget('999', 'nosy', []), [])
+
class ROTest(MyTestCase):
def setUp(self):
# remove previous test, ignore errors