Using pre_SubmitIssue and post_SubmitIssue to customize issue adding
11 Feb 2008
If you want to customize the way issues are added without rewriting the code you can use the two hooks pre_SubmitIssue and post_SubmitIssue.
Version requirement:
Suppose you want to add a custom field or you have some very special requirements for how issues are added there are two hooks you can set that gets called after the validation of input called pre_SubmitIssue() after after the issue has been created and indexed (and before notification being sent) called post_SubmitIssue(). These have to be callable Zope objects. The easiest thing is to create a Script (Python) inside the issuetracker. Here's some example code. Note that the script doesn't take any parameters so if you want to dig into the validation perhaps you have to do that with the context's 'REQUEST':
## Script (Python) "pre_SubmitIssue"
##parameters=
##title=
##
request = context.REQUEST
title = request.get('title',u'')
if title.lower().startswith(u'a'):
return {'title':u'Subject line must NOT start with an A'}
As a special magical rule, if the pre_SubmitIssue() script returns a dictionary, that's added to the validation errors. If this doesn't make sense right now, just try it it like the script above and see what happens when you try to save the issue.
Here's an example script that is called after the issue is created. Note now that this script is called with the issue object as the one and only parameter. It doesn't matter what you return in the script so if you want to stop the whole submission for some reason you can raise a Python error and the transaction machinery will take care of everything. This example increases the chosen urgency option up one notch if the selected section was Security:
## Script (Python) "post_SubmitIssue"
##parameters=issue
##title=
##
if 'Security' in issue.getSections():
# increase the urgency by one notch
urgency = issue.getUrgency()
options = issue.getUrgencyOptions() # acquired
try:
urgency = options[options.index(urgency)+1]
issue.editIssueDetails(urgency=urgency)
except IndexError:
# was already at the topmost
pass