comparison doc/customizing.txt @ 1270:c3424abf7f77

added ability to implement new templating utility methods
author Richard Jones <richard@users.sourceforge.net>
date Fri, 11 Oct 2002 01:26:43 +0000
parents a66dd1573ebd
children 0c0494deb09f
comparison
equal deleted inserted replaced
1269:3816e2d6cf6e 1270:c3424abf7f77
1 =================== 1 ===================
2 Customising Roundup 2 Customising Roundup
3 =================== 3 ===================
4 4
5 :Version: $Revision: 1.56 $ 5 :Version: $Revision: 1.57 $
6 6
7 .. This document borrows from the ZopeBook section on ZPT. The original is at: 7 .. This document borrows from the ZopeBook section on ZPT. The original is at:
8 http://www.zope.org/Documentation/Books/ZopeBook/current/ZPT.stx 8 http://www.zope.org/Documentation/Books/ZopeBook/current/ZPT.stx
9 9
10 .. contents:: 10 .. contents::
1332 1332
1333 1333
1334 The utils variable 1334 The utils variable
1335 ~~~~~~~~~~~~~~~~~~ 1335 ~~~~~~~~~~~~~~~~~~
1336 1336
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.
1338 1339
1339 =============== ============================================================= 1340 =============== =============================================================
1340 Method Description 1341 Method Description
1341 =============== ============================================================= 1342 =============== =============================================================
1342 Batch return a batch object using the supplied list 1343 Batch return a batch object using the supplied list
1343 =============== ============================================================= 1344 =============== =============================================================
1345
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.
1344 1351
1345 Batching 1352 Batching
1346 :::::::: 1353 ::::::::
1347 1354
1348 Use Batch to turn a list of items, or item ids of a given class, into a series 1355 Use Batch to turn a list of items, or item ids of a given class, into a series
2518 2525
2519 Note that the "context/submit" command usually handles all that for you - 2526 Note that the "context/submit" command usually handles all that for you -
2520 isn't it handy? The important change is setting the action to 2527 isn't it handy? The important change is setting the action to
2521 "edit_with_timelog" for edit operations (where the item exists) 2528 "edit_with_timelog" for edit operations (where the item exists)
2522 2529
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::
2524 2554
2525 <table class="otherinfo" tal:condition="context/times"> 2555 <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>
2527 <tr><th>Date</th><th>Period</th><th>Logged By</th></tr> 2559 <tr><th>Date</th><th>Period</th><th>Logged By</th></tr>
2528 <tr tal:repeat="time context/times"> 2560 <tr tal:repeat="time context/times">
2529 <td tal:content="time/creation"></td> 2561 <td tal:content="time/creation"></td>
2530 <td tal:content="time/period"></td> 2562 <td tal:content="time/period"></td>
2531 <td tal:content="time/creator"></td> 2563 <td tal:content="time/creator"></td>
2532 </tr> 2564 </tr>
2533 </table> 2565 </table>
2534 2566
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
2536 2568 of the ``totalTimeSpent`` method which will total up the times for the
2537 6. If you're using a persistent web server - roundup-server or mod_python for 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).
2571
2572 8. If you're using a persistent web server - roundup-server or mod_python for
2538 example - then you'll need to restart that to pick up the code changes. 2573 example - then you'll need to restart that to pick up the code changes.
2539 When that's done, you'll be able to use the new time logging interface. 2574 When that's done, you'll be able to use the new time logging interface.
2540 2575
2541 2576
2542 ------------------- 2577 -------------------

Roundup Issue Tracker: http://roundup-tracker.org/