IssueTrackerProduct

A user friendly bug tracking web application for Zope

Run reports with changing variables that can't be set staticallyRun reports with changing variables that can't be set statically

25 Oct 2005

If you are familiar with writing Issue Tracker Report Scripts you might need to pass a variable to the report script that changes every time such as dates or other booleans. This How to shows how to accomplish that.

The Issue Tracker Report Scripts that you create via the ZMI or from downloading simple examples from this site don't have any other parameters other than the issue it does a test on.

A way around this is to use the REQUEST object to pass in variable from somewhere else such as a custom form where you fill in the values for these parameters. Let's for example look at a Issue Tracker Report Script that uses a since_date variable to "calculate" which issues to include in the report. Go to your issuetracker's ZMI inside Reports some something like http://localhost:8080/issues/Reports/manage and select "Issue Tracker Report Script" from the dropdown. Enter this:

 Id: Issues-completed-since-a-variable-date

Then, when you can enter this code:

 rget = context.REQUEST.get
 rset = context.REQUEST.set
 if issue.getStatus().lower() in ('completed','rejected'):
    if not rget('since_date'):
        raise KeyError, "Variable 'since_date' not a passed parameter"
    elif same_type(rget('since_date'), 's'):
        rset('since_date', context.ZopeTime(rget('since_date')))
    variable_date = rget('since_date')
    if issue.getModifyDate() >= variable_date:
        return True
 return False

Now you have a Report script that will fail to run if you don't run it with the since_date REQUEST variable available. Now you need to create a page that starts running this report but with the parameter passed. Go back to the ZMI at http://localhost:8080/issues/Reports/manage and select Page Template from the drop down:

 Id: Completed-since

And enter the following Page Template code that makes it possible for you to reuse the header and footer of the issuetracker instance you have:

 
 
Show completed issues
Since:

Now, to test this all you have to do is to simply visit this Page Template at http://localhost:8080/issues/Reports/Completed-since

It's just one of many many ways that this can be used. Hopefully this howto is inspirational for you to write your own reports with non-static variables.

<<< Return to all how-tos