From 6380caf023076852b836da7931252b340c6b0235 Mon Sep 17 00:00:00 2001 From: richard Date: Fri, 14 Feb 2003 00:31:46 +0000 Subject: [PATCH] - 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. git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@1509 57a73879-2fb5-44c3-a270-3262357dd7e2 --- CHANGES.txt | 2 ++ roundup/backends/back_anydbm.py | 31 +++++++++++++++++++++++-------- roundup/backends/back_metakit.py | 10 ++++++++-- roundup/backends/rdbms_common.py | 29 ++++++++++++++++++++++------- roundup/cgi/client.py | 3 +-- test/test_cgi.py | 8 +++++--- 6 files changed, 61 insertions(+), 22 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index dd58c3d..45ab7bf 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -54,6 +54,8 @@ are given with the most recent entry first. - the colon ":" special form variable designator may now be any of : + @ - trackers' templates directory can contain subdirectories with static files (e.g. images). They are accessible naturally: _file/images/img.gif +- altered Class.create() and FileClass.create() methods to make "content" + property available in auditors 2003-??-?? 0.5.6 diff --git a/roundup/backends/back_anydbm.py b/roundup/backends/back_anydbm.py index 8d389c3..1971cca 100644 --- a/roundup/backends/back_anydbm.py +++ b/roundup/backends/back_anydbm.py @@ -15,7 +15,7 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -#$Id: back_anydbm.py,v 1.102 2003-02-13 07:33:38 richard Exp $ +#$Id: back_anydbm.py,v 1.103 2003-02-14 00:31:44 richard Exp $ ''' This module defines a backend that saves the hyperdatabase in a database chosen by anydbm. It is guaranteed to always be available in python @@ -765,6 +765,14 @@ class Class(hyperdb.Class): These operations trigger detectors and can be vetoed. Attempts to modify the "creation" or "activity" properties cause a KeyError. ''' + self.fireAuditors('create', None, propvalues) + newid = self.create_inner(**propvalues) + self.fireReactors('create', newid, None) + return newid + + def create_inner(self, **propvalues): + ''' Called by create, in-between the audit and react calls. + ''' if propvalues.has_key('id'): raise KeyError, '"id" is reserved' @@ -773,9 +781,6 @@ class Class(hyperdb.Class): if propvalues.has_key('creation') or propvalues.has_key('activity'): raise KeyError, '"creation" and "activity" are reserved' - - self.fireAuditors('create', None, propvalues) - # new node's id newid = self.db.newid(self.classname) @@ -895,8 +900,6 @@ class Class(hyperdb.Class): if self.do_journal: self.db.addjournal(self.classname, newid, 'create', {}) - self.fireReactors('create', newid, None) - return newid def export_list(self, propnames, nodeid): @@ -1888,11 +1891,23 @@ class FileClass(Class): default_mime_type = 'text/plain' def create(self, **propvalues): - ''' snaffle the file propvalue and store in a file + ''' Snarf the "content" propvalue and store in a file ''' + # we need to fire the auditors now, or the content property won't + # be in propvalues for the auditors to play with + self.fireAuditors('create', None, propvalues) + + # now remove the content property so it's not stored in the db content = propvalues['content'] del propvalues['content'] - newid = Class.create(self, **propvalues) + + # do the database create + newid = Class.create_inner(self, **propvalues) + + # fire reactors + self.fireReactors('create', newid, None) + + # store off the content as a file self.db.storefile(self.classname, newid, None, content) return newid diff --git a/roundup/backends/back_metakit.py b/roundup/backends/back_metakit.py index 711a41b..9e5a8b8 100755 --- a/roundup/backends/back_metakit.py +++ b/roundup/backends/back_metakit.py @@ -325,6 +325,11 @@ class Class: # --- the hyperdb.Class methods def create(self, **propvalues): self.fireAuditors('create', None, propvalues) + newid = self.create_inner(**propvalues) + # self.set() (called in self.create_inner()) does reactors) + return newid + + def create_inner(self, **propvalues): rowdict = {} rowdict['id'] = newid = self.maxid self.maxid += 1 @@ -606,7 +611,7 @@ class Class: row.creation = int(time.time()) if not row.creator: row.creator = self.db.curuserid - + self.db.dirty = 1 if self.do_journal: if isnew: @@ -1219,9 +1224,10 @@ class FileClass(Class): return x def create(self, **propvalues): + self.fireAuditors('create', None, propvalues) content = propvalues['content'] del propvalues['content'] - newid = Class.create(self, **propvalues) + newid = Class.create_inner(self, **propvalues) if not content: return newid nm = bnm = '%s%s' % (self.classname, newid) diff --git a/roundup/backends/rdbms_common.py b/roundup/backends/rdbms_common.py index 1214555..1fa6cd8 100644 --- a/roundup/backends/rdbms_common.py +++ b/roundup/backends/rdbms_common.py @@ -1,4 +1,4 @@ -# $Id: rdbms_common.py,v 1.32 2003-02-12 00:00:25 richard Exp $ +# $Id: rdbms_common.py,v 1.33 2003-02-14 00:31:45 richard Exp $ ''' Relational database (SQL) backend common code. Basics: @@ -985,6 +985,14 @@ class Class(hyperdb.Class): If an id in a link or multilink property does not refer to a valid node, an IndexError is raised. ''' + self.fireAuditors('create', None, propvalues) + newid = self.create_inner(**propvalues) + self.fireReactors('create', newid, None) + return newid + + def create_inner(self, **propvalues): + ''' Called by create, in-between the audit and react calls. + ''' if propvalues.has_key('id'): raise KeyError, '"id" is reserved' @@ -994,8 +1002,6 @@ class Class(hyperdb.Class): if propvalues.has_key('creation') or propvalues.has_key('activity'): raise KeyError, '"creation" and "activity" are reserved' - self.fireAuditors('create', None, propvalues) - # new node's id newid = self.db.newid(self.classname) @@ -1115,8 +1121,6 @@ class Class(hyperdb.Class): if self.do_journal: self.db.addjournal(self.classname, newid, 'create', {}) - self.fireReactors('create', newid, None) - return newid def export_list(self, propnames, nodeid): @@ -1987,9 +1991,21 @@ class FileClass(Class): def create(self, **propvalues): ''' snaffle the file propvalue and store in a file ''' + # we need to fire the auditors now, or the content property won't + # be in propvalues for the auditors to play with + self.fireAuditors('create', None, propvalues) + + # now remove the content property so it's not stored in the db content = propvalues['content'] del propvalues['content'] - newid = Class.create(self, **propvalues) + + # do the database create + newid = Class.create_inner(self, **propvalues) + + # fire reactors + self.fireReactors('create', newid, None) + + # store off the content as a file self.db.storefile(self.classname, newid, None, content) return newid @@ -2016,7 +2032,6 @@ class FileClass(Class): def get(self, nodeid, propname, default=_marker, cache=1): ''' trap the content propname and get it from the file ''' - poss_msg = 'Possibly a access right configuration problem.' if propname == 'content': try: diff --git a/roundup/cgi/client.py b/roundup/cgi/client.py index ac8d9d4..10015b3 100644 --- a/roundup/cgi/client.py +++ b/roundup/cgi/client.py @@ -1,4 +1,4 @@ -# $Id: client.py,v 1.84 2003-02-13 12:10:34 kedder Exp $ +# $Id: client.py,v 1.85 2003-02-14 00:31:46 richard Exp $ __doc__ = """ WWW request handler (also used in the stand-alone server). @@ -1021,7 +1021,6 @@ class Client: if newids is None: newids = {} for (cn, nodeid), props in all_props.items(): - print ((cn, nodeid), props) if int(nodeid) > 0: # make changes to the node props = self._changenode(cn, nodeid, props) diff --git a/test/test_cgi.py b/test/test_cgi.py index b0a2cd0..4cb0113 100644 --- a/test/test_cgi.py +++ b/test/test_cgi.py @@ -8,7 +8,7 @@ # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # -# $Id: test_cgi.py,v 1.8 2003-02-13 07:38:34 richard Exp $ +# $Id: test_cgi.py,v 1.9 2003-02-14 00:31:46 richard Exp $ import unittest, os, shutil, errno, sys, difflib, cgi @@ -388,8 +388,10 @@ class FormTestCase(unittest.TestCase): {'test-1@:link:link': 'issue'}) def testBackwardsCompat(self): - self.assertEqual(self.parseForm({':note': 'spam'}, 'issue'), - ({('issue', None): {}, ('msg', '-1'): {'content': 'spam'}}, + res = self.parseForm({':note': 'spam'}, 'issue') + date = res[0][('msg', '-1')]['date'] + self.assertEqual(res, ({('issue', None): {}, ('msg', '-1'): + {'content': 'spam', 'author': '1', 'date': date}}, [('issue', None, 'messages', [('msg', '-1')])])) file = FileUpload('foo', 'foo.txt') self.assertEqual(self.parseForm({':file': file}, 'issue'), -- 2.39.5