Skip to content

Commit 80c61aa

Browse files
author
Richard Jones
committed
Altered Class.create() and FileClass.create() methods...
...to make "content" property available in auditors Added "author" and "date" props to messages created by ":note". It might be useful to keep that alive as a convenience variable.
1 parent b6ea7e8 commit 80c61aa

File tree

6 files changed

+61
-22
lines changed

6 files changed

+61
-22
lines changed

CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ are given with the most recent entry first.
5454
- the colon ":" special form variable designator may now be any of : + @
5555
- trackers' templates directory can contain subdirectories with static files
5656
(e.g. images). They are accessible naturally: _file/images/img.gif
57+
- altered Class.create() and FileClass.create() methods to make "content"
58+
property available in auditors
5759

5860

5961
2003-??-?? 0.5.6

roundup/backends/back_anydbm.py

Lines changed: 23 additions & 8 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: back_anydbm.py,v 1.102 2003-02-13 07:33:38 richard Exp $
18+
#$Id: back_anydbm.py,v 1.103 2003-02-14 00:31:44 richard Exp $
1919
'''
2020
This module defines a backend that saves the hyperdatabase in a database
2121
chosen by anydbm. It is guaranteed to always be available in python
@@ -765,6 +765,14 @@ def create(self, **propvalues):
765765
These operations trigger detectors and can be vetoed. Attempts
766766
to modify the "creation" or "activity" properties cause a KeyError.
767767
'''
768+
self.fireAuditors('create', None, propvalues)
769+
newid = self.create_inner(**propvalues)
770+
self.fireReactors('create', newid, None)
771+
return newid
772+
773+
def create_inner(self, **propvalues):
774+
''' Called by create, in-between the audit and react calls.
775+
'''
768776
if propvalues.has_key('id'):
769777
raise KeyError, '"id" is reserved'
770778

@@ -773,9 +781,6 @@ def create(self, **propvalues):
773781

774782
if propvalues.has_key('creation') or propvalues.has_key('activity'):
775783
raise KeyError, '"creation" and "activity" are reserved'
776-
777-
self.fireAuditors('create', None, propvalues)
778-
779784
# new node's id
780785
newid = self.db.newid(self.classname)
781786

@@ -895,8 +900,6 @@ def create(self, **propvalues):
895900
if self.do_journal:
896901
self.db.addjournal(self.classname, newid, 'create', {})
897902

898-
self.fireReactors('create', newid, None)
899-
900903
return newid
901904

902905
def export_list(self, propnames, nodeid):
@@ -1888,11 +1891,23 @@ class FileClass(Class):
18881891
default_mime_type = 'text/plain'
18891892

18901893
def create(self, **propvalues):
1891-
''' snaffle the file propvalue and store in a file
1894+
''' Snarf the "content" propvalue and store in a file
18921895
'''
1896+
# we need to fire the auditors now, or the content property won't
1897+
# be in propvalues for the auditors to play with
1898+
self.fireAuditors('create', None, propvalues)
1899+
1900+
# now remove the content property so it's not stored in the db
18931901
content = propvalues['content']
18941902
del propvalues['content']
1895-
newid = Class.create(self, **propvalues)
1903+
1904+
# do the database create
1905+
newid = Class.create_inner(self, **propvalues)
1906+
1907+
# fire reactors
1908+
self.fireReactors('create', newid, None)
1909+
1910+
# store off the content as a file
18961911
self.db.storefile(self.classname, newid, None, content)
18971912
return newid
18981913

roundup/backends/back_metakit.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,11 @@ def react(self, event, detector):
325325
# --- the hyperdb.Class methods
326326
def create(self, **propvalues):
327327
self.fireAuditors('create', None, propvalues)
328+
newid = self.create_inner(**propvalues)
329+
# self.set() (called in self.create_inner()) does reactors)
330+
return newid
331+
332+
def create_inner(self, **propvalues):
328333
rowdict = {}
329334
rowdict['id'] = newid = self.maxid
330335
self.maxid += 1
@@ -606,7 +611,7 @@ def set(self, nodeid, **propvalues):
606611
row.creation = int(time.time())
607612
if not row.creator:
608613
row.creator = self.db.curuserid
609-
614+
610615
self.db.dirty = 1
611616
if self.do_journal:
612617
if isnew:
@@ -1219,9 +1224,10 @@ def get(self, nodeid, propname, default=_marker, cache=1):
12191224
return x
12201225

12211226
def create(self, **propvalues):
1227+
self.fireAuditors('create', None, propvalues)
12221228
content = propvalues['content']
12231229
del propvalues['content']
1224-
newid = Class.create(self, **propvalues)
1230+
newid = Class.create_inner(self, **propvalues)
12251231
if not content:
12261232
return newid
12271233
nm = bnm = '%s%s' % (self.classname, newid)

roundup/backends/rdbms_common.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: rdbms_common.py,v 1.32 2003-02-12 00:00:25 richard Exp $
1+
# $Id: rdbms_common.py,v 1.33 2003-02-14 00:31:45 richard Exp $
22
''' Relational database (SQL) backend common code.
33
44
Basics:
@@ -985,6 +985,14 @@ def create(self, **propvalues):
985985
If an id in a link or multilink property does not refer to a valid
986986
node, an IndexError is raised.
987987
'''
988+
self.fireAuditors('create', None, propvalues)
989+
newid = self.create_inner(**propvalues)
990+
self.fireReactors('create', newid, None)
991+
return newid
992+
993+
def create_inner(self, **propvalues):
994+
''' Called by create, in-between the audit and react calls.
995+
'''
988996
if propvalues.has_key('id'):
989997
raise KeyError, '"id" is reserved'
990998

@@ -994,8 +1002,6 @@ def create(self, **propvalues):
9941002
if propvalues.has_key('creation') or propvalues.has_key('activity'):
9951003
raise KeyError, '"creation" and "activity" are reserved'
9961004

997-
self.fireAuditors('create', None, propvalues)
998-
9991005
# new node's id
10001006
newid = self.db.newid(self.classname)
10011007

@@ -1115,8 +1121,6 @@ def create(self, **propvalues):
11151121
if self.do_journal:
11161122
self.db.addjournal(self.classname, newid, 'create', {})
11171123

1118-
self.fireReactors('create', newid, None)
1119-
11201124
return newid
11211125

11221126
def export_list(self, propnames, nodeid):
@@ -1987,9 +1991,21 @@ class FileClass(Class):
19871991
def create(self, **propvalues):
19881992
''' snaffle the file propvalue and store in a file
19891993
'''
1994+
# we need to fire the auditors now, or the content property won't
1995+
# be in propvalues for the auditors to play with
1996+
self.fireAuditors('create', None, propvalues)
1997+
1998+
# now remove the content property so it's not stored in the db
19901999
content = propvalues['content']
19912000
del propvalues['content']
1992-
newid = Class.create(self, **propvalues)
2001+
2002+
# do the database create
2003+
newid = Class.create_inner(self, **propvalues)
2004+
2005+
# fire reactors
2006+
self.fireReactors('create', newid, None)
2007+
2008+
# store off the content as a file
19932009
self.db.storefile(self.classname, newid, None, content)
19942010
return newid
19952011

@@ -2016,7 +2032,6 @@ def import_list(self, propnames, proplist):
20162032
def get(self, nodeid, propname, default=_marker, cache=1):
20172033
''' trap the content propname and get it from the file
20182034
'''
2019-
20202035
poss_msg = 'Possibly a access right configuration problem.'
20212036
if propname == 'content':
20222037
try:

roundup/cgi/client.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: client.py,v 1.84 2003-02-13 12:10:34 kedder Exp $
1+
# $Id: client.py,v 1.85 2003-02-14 00:31:46 richard Exp $
22

33
__doc__ = """
44
WWW request handler (also used in the stand-alone server).
@@ -1021,7 +1021,6 @@ def _editnodes(self, all_props, all_links, newids=None):
10211021
if newids is None:
10221022
newids = {}
10231023
for (cn, nodeid), props in all_props.items():
1024-
print ((cn, nodeid), props)
10251024
if int(nodeid) > 0:
10261025
# make changes to the node
10271026
props = self._changenode(cn, nodeid, props)

test/test_cgi.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# but WITHOUT ANY WARRANTY; without even the implied warranty of
99
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1010
#
11-
# $Id: test_cgi.py,v 1.8 2003-02-13 07:38:34 richard Exp $
11+
# $Id: test_cgi.py,v 1.9 2003-02-14 00:31:46 richard Exp $
1212

1313
import unittest, os, shutil, errno, sys, difflib, cgi
1414

@@ -388,8 +388,10 @@ def testLinkBadDesignator(self):
388388
{'test-1@:link:link': 'issue'})
389389

390390
def testBackwardsCompat(self):
391-
self.assertEqual(self.parseForm({':note': 'spam'}, 'issue'),
392-
({('issue', None): {}, ('msg', '-1'): {'content': 'spam'}},
391+
res = self.parseForm({':note': 'spam'}, 'issue')
392+
date = res[0][('msg', '-1')]['date']
393+
self.assertEqual(res, ({('issue', None): {}, ('msg', '-1'):
394+
{'content': 'spam', 'author': '1', 'date': date}},
393395
[('issue', None, 'messages', [('msg', '-1')])]))
394396
file = FileUpload('foo', 'foo.txt')
395397
self.assertEqual(self.parseForm({':file': file}, 'issue'),

0 commit comments

Comments
 (0)