1515# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717#
18- #$Id: back_anydbm.py,v 1.82 2002-09-20 01:20:31 richard Exp $
18+ #$Id: back_anydbm.py,v 1.83 2002-09-20 05:08:00 richard Exp $
1919'''
2020This module defines a backend that saves the hyperdatabase in a database
2121chosen by anydbm. It is guaranteed to always be available in python
@@ -73,11 +73,21 @@ def __init__(self, config, journaltag=None):
7373 os .umask (0002 )
7474
7575 def post_init (self ):
76- '''Called once the schema initialisation has finished.'''
76+ ''' Called once the schema initialisation has finished.
77+ '''
7778 # reindex the db if necessary
7879 if self .indexer .should_reindex ():
7980 self .reindex ()
8081
82+ # figure the "curuserid"
83+ if self .journaltag is None :
84+ self .curuserid = None
85+ elif self .journaltag == 'admin' :
86+ # admin user may not exist, but always has ID 1
87+ self .curuserid = '1'
88+ else :
89+ self .curuserid = self .user .lookup (self .journaltag )
90+
8191 def reindex (self ):
8292 for klass in self .classes .values ():
8393 for nodeid in klass .list ():
@@ -237,11 +247,13 @@ def addnode(self, classname, nodeid, node):
237247 if __debug__ :
238248 print >> hyperdb .DEBUG , 'addnode' , (self , classname , nodeid , node )
239249
240- # add in the "calculated" properties (dupe so we don't affect
241- # calling code's node assumptions)
242- node = node .copy ()
243- node ['creator' ] = self .journaltag
244- node ['creation' ] = node ['activity' ] = date .Date ()
250+ # we'll be supplied these props if we're doing an import
251+ if not node .has_key ('creator' ):
252+ # add in the "calculated" properties (dupe so we don't affect
253+ # calling code's node assumptions)
254+ node = node .copy ()
255+ node ['creator' ] = self .curuserid
256+ node ['creation' ] = node ['activity' ] = date .Date ()
245257
246258 self .newnodes .setdefault (classname , {})[nodeid ] = 1
247259 self .cache .setdefault (classname , {})[nodeid ] = node
@@ -631,7 +643,7 @@ def doSaveJournal(self, classname, nodeid, action, params, creator,
631643 if creator :
632644 journaltag = creator
633645 else :
634- journaltag = self .journaltag
646+ journaltag = self .curuserid
635647 if creation :
636648 journaldate = creation .serialise ()
637649 else :
@@ -949,7 +961,10 @@ def import_list(self, propnames, proplist):
949961 value = pwd
950962 d [propname ] = value
951963
952- # extract the extraneous journalling gumpf and nuke it
964+ # add the node and journal
965+ self .db .addnode (self .classname , newid , d )
966+
967+ # extract the journalling stuff and nuke it
953968 if d .has_key ('creator' ):
954969 creator = d ['creator' ]
955970 del d ['creator' ]
@@ -963,8 +978,6 @@ def import_list(self, propnames, proplist):
963978 if d .has_key ('activity' ):
964979 del d ['activity' ]
965980
966- # add the node and journal
967- self .db .addnode (self .classname , newid , d )
968981 self .db .addjournal (self .classname , newid , 'create' , d , creator ,
969982 creation )
970983 return newid
@@ -1020,9 +1033,19 @@ def get(self, nodeid, propname, default=_marker, cache=1):
10201033 raise ValueError , 'Journalling is disabled for this class'
10211034 journal = self .db .getjournal (self .classname , nodeid )
10221035 if journal :
1023- return self .db .getjournal (self .classname , nodeid )[0 ][2 ]
1036+ num_re = re .compile ('^\d+$' )
1037+ value = self .db .getjournal (self .classname , nodeid )[0 ][2 ]
1038+ if num_re .match (value ):
1039+ return value
1040+ else :
1041+ # old-style "username" journal tag
1042+ try :
1043+ return self .db .user .lookup (value )
1044+ except KeyError :
1045+ # user's been retired, return admin
1046+ return '1'
10241047 else :
1025- return self .db .journaltag
1048+ return self .db .curuserid
10261049
10271050 # get the property (raises KeyErorr if invalid)
10281051 prop = self .properties [propname ]
@@ -1779,9 +1802,7 @@ def getprops(self, protected=1):
17791802 d ['id' ] = String ()
17801803 d ['creation' ] = hyperdb .Date ()
17811804 d ['activity' ] = hyperdb .Date ()
1782- # can't be a link to user because the user might have been
1783- # retired since the journal entry was created
1784- d ['creator' ] = hyperdb .String ()
1805+ d ['creator' ] = hyperdb .Link ('user' )
17851806 return d
17861807
17871808 def addprop (self , ** properties ):
0 commit comments