Skip to content

Commit b12584f

Browse files
author
Roche Compaan
committed
Journal entries for link and multilink properties can now be switched on or off.
1 parent 9078324 commit b12584f

File tree

3 files changed

+88
-21
lines changed

3 files changed

+88
-21
lines changed

CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ are given with the most recent entry first.
44
2002-01-?? - 0.4.0??
55
Feature:
66
. much nicer history display (actualy real handling of property types etc)
7+
. journal entries for link and mutlilink properties can be switched on or
8+
off
79

810
Fixed:
911
. handle attachments with no name (eg tnef)

roundup/hyperdb.py

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: hyperdb.py,v 1.49 2002-01-16 07:02:57 richard Exp $
18+
# $Id: hyperdb.py,v 1.50 2002-01-19 13:16:04 rochecompaan Exp $
1919

2020
__doc__ = """
2121
Hyperdatabase implementation, especially field types.
@@ -54,17 +54,19 @@ def __repr__(self):
5454
class Link:
5555
"""An object designating a Link property that links to a
5656
node in a specified class."""
57-
def __init__(self, classname):
57+
def __init__(self, classname, do_journal='no'):
5858
self.classname = classname
59+
self.do_journal = do_journal == 'yes'
5960
def __repr__(self):
6061
return '<%s to "%s">'%(self.__class__, self.classname)
6162

6263
class Multilink:
6364
"""An object designating a Multilink property that links
6465
to nodes in a specified class.
6566
"""
66-
def __init__(self, classname):
67+
def __init__(self, classname, do_journal='no'):
6768
self.classname = classname
69+
self.do_journal = do_journal == 'yes'
6870
def __repr__(self):
6971
return '<%s to "%s">'%(self.__class__, self.classname)
7072

@@ -309,8 +311,9 @@ def create(self, **propvalues):
309311
propvalues[key] = value
310312

311313
# register the link with the newly linked node
312-
self.db.addjournal(link_class, value, 'link',
313-
(self.classname, newid, key))
314+
if self.properties[key].do_journal:
315+
self.db.addjournal(link_class, value, 'link',
316+
(self.classname, newid, key))
314317

315318
elif isinstance(prop, Multilink):
316319
if type(value) != type([]):
@@ -336,8 +339,9 @@ def create(self, **propvalues):
336339
if not self.db.hasnode(link_class, id):
337340
raise IndexError, '%s has no node %s'%(link_class, id)
338341
# register the link with the newly linked node
339-
self.db.addjournal(link_class, id, 'link',
340-
(self.classname, newid, key))
342+
if self.properties[key].do_journal:
343+
self.db.addjournal(link_class, id, 'link',
344+
(self.classname, newid, key))
341345

342346
elif isinstance(prop, String):
343347
if type(value) != type(''):
@@ -505,15 +509,16 @@ class or a KeyError is raised.
505509
if not self.db.hasnode(link_class, value):
506510
raise IndexError, '%s has no node %s'%(link_class, value)
507511

508-
# register the unlink with the old linked node
509-
if node[key] is not None:
510-
self.db.addjournal(link_class, node[key], 'unlink',
511-
(self.classname, nodeid, key))
512+
if self.properties[key].do_journal:
513+
# register the unlink with the old linked node
514+
if node[key] is not None:
515+
self.db.addjournal(link_class, node[key], 'unlink',
516+
(self.classname, nodeid, key))
512517

513-
# register the link with the newly linked node
514-
if value is not None:
515-
self.db.addjournal(link_class, value, 'link',
516-
(self.classname, nodeid, key))
518+
# register the link with the newly linked node
519+
if value is not None:
520+
self.db.addjournal(link_class, value, 'link',
521+
(self.classname, nodeid, key))
517522

518523
elif isinstance(prop, Multilink):
519524
if type(value) != type([]):
@@ -543,19 +548,22 @@ class or a KeyError is raised.
543548
if id in value:
544549
continue
545550
# register the unlink with the old linked node
546-
self.db.addjournal(link_class, id, 'unlink',
547-
(self.classname, nodeid, key))
551+
if self.properties[key].do_journal:
552+
self.db.addjournal(link_class, id, 'unlink',
553+
(self.classname, nodeid, key))
548554
l.remove(id)
549555

550556
# handle additions
551557
for id in value:
552558
if not self.db.hasnode(link_class, id):
553-
raise IndexError, '%s has no node %s'%(link_class, id)
559+
raise IndexError, '%s has no node %s'%(
560+
link_class, id)
554561
if id in l:
555562
continue
556563
# register the link with the newly linked node
557-
self.db.addjournal(link_class, id, 'link',
558-
(self.classname, nodeid, key))
564+
if self.properties[key].do_journal:
565+
self.db.addjournal(link_class, id, 'link',
566+
(self.classname, nodeid, key))
559567
l.append(id)
560568

561569
elif isinstance(prop, String):
@@ -1047,6 +1055,10 @@ def Choice(name, *options):
10471055

10481056
#
10491057
# $Log: not supported by cvs2svn $
1058+
# Revision 1.49 2002/01/16 07:02:57 richard
1059+
# . lots of date/interval related changes:
1060+
# - more relaxed date format for input
1061+
#
10501062
# Revision 1.48 2002/01/14 06:32:34 richard
10511063
# . #502951 ] adding new properties to old database
10521064
#

test/test_db.py

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: test_db.py,v 1.14 2002-01-16 07:02:57 richard Exp $
18+
# $Id: test_db.py,v 1.15 2002-01-19 13:16:04 rochecompaan Exp $
1919

2020
import unittest, os, shutil
2121

@@ -190,6 +190,55 @@ def testExceptions(self):
190190
ar(IndexError, self.db.issue.set, '1', title='foo', status='1',
191191
nosy=['10'])
192192

193+
def testJournals(self):
194+
self.db.issue.addprop(fixer=Link("user", do_journal='yes'))
195+
self.db.user.create(username="mary")
196+
self.db.user.create(username="pete")
197+
self.db.issue.create(title="spam", status='1')
198+
self.db.commit()
199+
200+
# journal entry for issue create
201+
journal = self.db.getjournal('issue', '1')
202+
self.assertEqual(1, len(journal))
203+
(nodeid, date_stamp, journaltag, action, params) = journal[0]
204+
self.assertEqual(nodeid, '1')
205+
self.assertEqual(journaltag, 'test')
206+
self.assertEqual(action, 'create')
207+
keys = params.keys()
208+
keys.sort()
209+
self.assertEqual(keys, ['deadline', 'fixer', 'foo', 'nosy',
210+
'status', 'title'])
211+
self.assertEqual(None,params['deadline'])
212+
self.assertEqual(None,params['fixer'])
213+
self.assertEqual(None,params['foo'])
214+
self.assertEqual([],params['nosy'])
215+
self.assertEqual('1',params['status'])
216+
self.assertEqual('spam',params['title'])
217+
218+
# journal entry for link
219+
journal = self.db.getjournal('user', '1')
220+
self.assertEqual(1, len(journal))
221+
self.db.issue.set('1', fixer='1')
222+
self.db.commit()
223+
journal = self.db.getjournal('user', '1')
224+
self.assertEqual(2, len(journal))
225+
(nodeid, date_stamp, journaltag, action, params) = journal[1]
226+
self.assertEqual('1', nodeid)
227+
self.assertEqual('test', journaltag)
228+
self.assertEqual('link', action)
229+
self.assertEqual(('issue', '1', 'fixer'), params)
230+
231+
# journal entry for unlink
232+
self.db.issue.set('1', fixer='2')
233+
self.db.commit()
234+
journal = self.db.getjournal('user', '1')
235+
self.assertEqual(3, len(journal))
236+
(nodeid, date_stamp, journaltag, action, params) = journal[2]
237+
self.assertEqual('1', nodeid)
238+
self.assertEqual('test', journaltag)
239+
self.assertEqual('unlink', action)
240+
self.assertEqual(('issue', '1', 'fixer'), params)
241+
193242
def testRetire(self):
194243
pass
195244

@@ -285,6 +334,10 @@ def suite():
285334

286335
#
287336
# $Log: not supported by cvs2svn $
337+
# Revision 1.14 2002/01/16 07:02:57 richard
338+
# . lots of date/interval related changes:
339+
# - more relaxed date format for input
340+
#
288341
# Revision 1.13 2002/01/14 02:20:15 richard
289342
# . changed all config accesses so they access either the instance or the
290343
# config attriubute on the db. This means that all config is obtained from

0 commit comments

Comments
 (0)