[Python-checkins] r60863 - tracker/instances/jobs/detectors/statusauditor.py
martin.v.loewis
python-checkins at python.org
Sat Feb 16 19:21:40 CET 2008
Author: martin.v.loewis
Date: Sat Feb 16 19:21:40 2008
New Revision: 60863
Modified:
tracker/instances/jobs/detectors/statusauditor.py
Log:
Avoid status lookups in detector init.
Modified: tracker/instances/jobs/detectors/statusauditor.py
==============================================================================
--- tracker/instances/jobs/detectors/statusauditor.py (original)
+++ tracker/instances/jobs/detectors/statusauditor.py Sat Feb 16 19:21:40 2008
@@ -4,7 +4,7 @@
""" Make sure the status is set on new offers"""
if newvalues.has_key('status') and newvalues['status']:
- if newvalues['status'] == posted:
+ if db.status.get(newvalues['status'], 'name') == 'posted':
raise ValueError, "You can only set the offer to submitted, not posted"
return
@@ -15,7 +15,8 @@
def audit_status(db, cl, nodeid, newvalues):
"Prevent regular users from posting their offers themselves."
user = db.getuid()
- if newvalues.get('status') != posted:
+ if (newvalues.has_key('status') and
+ db.status.get(newvalues['status'], 'name') != 'posted'):
return
if db.user.get(user, 'roles').lower().find('editor') != -1:
# Ok if an editor posted it; set the posting date
@@ -29,7 +30,7 @@
db.config.options['TEMPLATES'].get(),
"posted.txt")
f = open(filename, "w")
- for offer in cl.filter(None, {'status':posted},
+ for offer in cl.filter(None, {'status':db.status.lookup('posted')},
sort=[('-','posted')]):
offer = cl.getnode(offer)
head = ""
@@ -60,13 +61,15 @@
f.close()
def generate(db, cl, nodeid, oldvalues):
- if cl.get(nodeid, 'status') == posted:
+ newstatus = cl.get(nodeid, 'status')
+ oldstatus = oldvalues['status']
+ posted = db.status.lookup('posted')
+ print oldstatus, newstatus, posted
+ if newstatus != oldstatus and (newstatus==posted or oldstatus==posted):
inner_generate(db,cl)
def init(db):
- global posted
- posted = db.status.lookup('posted')
# fire before changes are made
db.offer.audit('create', init_status)
db.offer.audit('set', audit_status)
More information about the Python-checkins
mailing list