22Customising Roundup
33===================
44
5- :Version: $Revision: 1.56 $
5+ :Version: $Revision: 1.57 $
66
77.. This document borrows from the ZopeBook section on ZPT. The original is at:
88 http://www.zope.org/Documentation/Books/ZopeBook/current/ZPT.stx
@@ -1334,14 +1334,21 @@ or the python expression::
13341334The utils variable
13351335~~~~~~~~~~~~~~~~~~
13361336
1337- Note: this is implemented by the roundup.cgi.templating.TemplatingUtils class.
1337+ Note: this is implemented by the roundup.cgi.templating.TemplatingUtils class,
1338+ but it may be extended as described below.
13381339
13391340=============== =============================================================
13401341Method Description
13411342=============== =============================================================
13421343Batch return a batch object using the supplied list
13431344=============== =============================================================
13441345
1346+ You may add additional utility methods by writing them in your tracker
1347+ ``interfaces.py`` module's ``TemplatingUtils`` class. See `adding a time log
1348+ to your issues`_ for an example. The TemplatingUtils class itself will have a
1349+ single attribute, ``client``, which may be used to access the ``client.db``
1350+ when you need to perform arbitrary database queries.
1351+
13451352Batching
13461353::::::::
13471354
@@ -2520,10 +2527,35 @@ able to give a summary of the total time spent on a particular issue.
25202527 isn't it handy? The important change is setting the action to
25212528 "edit_with_timelog" for edit operations (where the item exists)
25222529
2523- 6. Display the time log for an issue::
2530+ 6. We want to display a total of the time log times that have been accumulated
2531+ for an issue. To do this, we'll need to actually write some Python code,
2532+ since it's beyond the scope of PageTemplates to perform such calculations.
2533+ We do this by adding a method to the TemplatingUtils class in our tracker
2534+ ``interfaces.py`` module::
2535+
2536+
2537+ class TemplatingUtils:
2538+ ''' Methods implemented on this class will be available to HTML
2539+ templates through the 'utils' variable.
2540+ '''
2541+ def totalTimeSpent(self, times):
2542+ ''' Call me with a list of timelog items (which have an Interval
2543+ "period" property)
2544+ '''
2545+ total = Interval('')
2546+ for time in times:
2547+ total += time.period._value
2548+ return total
2549+
2550+ As indicated in the docstrings, we will be able to access the
2551+ ``totalTimeSpent`` method via the ``utils`` variable in our templates. See
2552+
2553+ 7. Display the time log for an issue::
25242554
25252555 <table class="otherinfo" tal:condition="context/times">
2526- <tr><th colspan="3" class="header">Time Log</th></tr>
2556+ <tr><th colspan="3" class="header">Time Log
2557+ <tal:block tal:replace="python:utils.totalTimeSpent(context.times)" />
2558+ </th></tr>
25272559 <tr><th>Date</th><th>Period</th><th>Logged By</th></tr>
25282560 <tr tal:repeat="time context/times">
25292561 <td tal:content="time/creation"></td>
@@ -2532,9 +2564,12 @@ able to give a summary of the total time spent on a particular issue.
25322564 </tr>
25332565 </table>
25342566
2535- I put this just above the Messages log in my issue display.
2567+ I put this just above the Messages log in my issue display. Note our use
2568+ of the ``totalTimeSpent`` method which will total up the times for the
2569+ issue and return a new Interval. That will be automatically displayed in
2570+ the template as text like "+ 1y 2:40" (1 year, 2 hours and 40 minutes).
25362571
2537- 6 . If you're using a persistent web server - roundup-server or mod_python for
2572+ 8 . If you're using a persistent web server - roundup-server or mod_python for
25382573 example - then you'll need to restart that to pick up the code changes.
25392574 When that's done, you'll be able to use the new time logging interface.
25402575
0 commit comments