Developer's Guide

  • Docs Home
  • Community Home

3. Adding Export Buttons to Reports

Adding an Export All button to a report is fairly straightforward. The overall format of the report markup looks something like this:

<tal:block tal:define="
objects python:here.ZenUsers.getAllThingsForReport();
objects python: (hasattr(request, 'doExport') and list(objects)) or objects;
tableName string: thisIsTheTableName;
batch python:here.ZenTableManager.getBatch(tableName,objects,
sortedHeader='getUserid');
exportFields python:['getUserid', 'id', 'delay',
'enabled', 'nextActiveNice', 'nextDurationNice',
'repeatNice', 'where'];
">
<tal:block metal:use-macro="here/reportMacros/macros/exportableReport">
<tal:block metal:fill-slot="report">

The normal report markup goes here

</tal:block>
</tal:block>
</tal:block

The first definition is a call to some method that retrieves the objects for the report. This might be a list, tuple or an iterable class.

If we are doing an export then we need this to be a list, so the second tal:define line makes sure we have a list in the event that we are doing an export. It's good to not do this if we are not doing an export. Large reports might run into performance issues if an iterable is converted to a list unnecessarily.

tablename is defined here for use by the getBatch() call that follows.

exportFields is a list of data to be included in the export. These can be attribute names or names of methods to call. See DataRoot.writeExportRows() for more details on what can be included in this list.

Within the <tal:block metal:fill-slot="report"></tal:block> block goes the report markup you would use when not including the export functionality.

Note

If the Export All button is mysteriously not doing anything you may need to be using zenTableNavigation/macros/navtool rather than zenTableNavigation/macros/navbody in your report. The former includes the <form> tag, the latter does not. If you are not providing a <form> tag then you need to use navtool so the export button is within a form.