From 14de4de61422ddfb69f4794d6ada3a17adbe1c68 Mon Sep 17 00:00:00 2001 From: richard Date: Fri, 11 Oct 2002 01:26:43 +0000 Subject: [PATCH] added ability to implement new templating utility methods git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@1343 57a73879-2fb5-44c3-a270-3262357dd7e2 --- CHANGES.txt | 4 +++ doc/customizing.txt | 47 +++++++++++++++++++++---- roundup/cgi/templating.py | 13 ++++++- roundup/templates/classic/interfaces.py | 8 ++++- roundup/templates/minimal/interfaces.py | 8 ++++- 5 files changed, 71 insertions(+), 9 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index be7a5e5..5bbc01a 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -20,6 +20,10 @@ are given with the most recent entry first. - fixed history to display username instead of userid - shipped templates didn't import all hyperdb types in dbinit.py - fixed bug in Interval serialisation +- handle "unset" status in status auditor (sf bug 621250) +- issues in 'done-cbb' are now also moved to 'chatting' on new messages +- implemented the missing Interval.__add__ +- added ability to implement new templating utility methods 2002-10-02 0.5.0 diff --git a/doc/customizing.txt b/doc/customizing.txt index 1e76c88..901f13a 100644 --- a/doc/customizing.txt +++ b/doc/customizing.txt @@ -2,7 +2,7 @@ Customising Roundup =================== -:Version: $Revision: 1.56 $ +:Version: $Revision: 1.57 $ .. This document borrows from the ZopeBook section on ZPT. The original is at: http://www.zope.org/Documentation/Books/ZopeBook/current/ZPT.stx @@ -1334,7 +1334,8 @@ or the python expression:: The utils variable ~~~~~~~~~~~~~~~~~~ -Note: this is implemented by the roundup.cgi.templating.TemplatingUtils class. +Note: this is implemented by the roundup.cgi.templating.TemplatingUtils class, +but it may be extended as described below. =============== ============================================================= Method Description @@ -1342,6 +1343,12 @@ Method Description Batch return a batch object using the supplied list =============== ============================================================= +You may add additional utility methods by writing them in your tracker +``interfaces.py`` module's ``TemplatingUtils`` class. See `adding a time log +to your issues`_ for an example. The TemplatingUtils class itself will have a +single attribute, ``client``, which may be used to access the ``client.db`` +when you need to perform arbitrary database queries. + Batching :::::::: @@ -2520,10 +2527,35 @@ able to give a summary of the total time spent on a particular issue. isn't it handy? The important change is setting the action to "edit_with_timelog" for edit operations (where the item exists) -6. Display the time log for an issue:: +6. We want to display a total of the time log times that have been accumulated + for an issue. To do this, we'll need to actually write some Python code, + since it's beyond the scope of PageTemplates to perform such calculations. + We do this by adding a method to the TemplatingUtils class in our tracker + ``interfaces.py`` module:: + + + class TemplatingUtils: + ''' Methods implemented on this class will be available to HTML + templates through the 'utils' variable. + ''' + def totalTimeSpent(self, times): + ''' Call me with a list of timelog items (which have an Interval + "period" property) + ''' + total = Interval('') + for time in times: + total += time.period._value + return total + + As indicated in the docstrings, we will be able to access the + ``totalTimeSpent`` method via the ``utils`` variable in our templates. See + +7. Display the time log for an issue:: - + @@ -2532,9 +2564,12 @@ able to give a summary of the total time spent on a particular issue.
Time Log
Time Log + +
DatePeriodLogged By
- I put this just above the Messages log in my issue display. + I put this just above the Messages log in my issue display. Note our use + of the ``totalTimeSpent`` method which will total up the times for the + issue and return a new Interval. That will be automatically displayed in + the template as text like "+ 1y 2:40" (1 year, 2 hours and 40 minutes). -6. If you're using a persistent web server - roundup-server or mod_python for +8. If you're using a persistent web server - roundup-server or mod_python for example - then you'll need to restart that to pick up the code changes. When that's done, you'll be able to use the new time logging interface. diff --git a/roundup/cgi/templating.py b/roundup/cgi/templating.py index 89e3eee..0a82a17 100644 --- a/roundup/cgi/templating.py +++ b/roundup/cgi/templating.py @@ -130,8 +130,19 @@ class RoundupPageTemplate(PageTemplate.PageTemplate): The current tracker config. *db* The current database, used to access arbitrary database items. + *utils* + This is a special class that has its base in the TemplatingUtils + class in this file. If the tracker interfaces module defines a + TemplatingUtils class then it is mixed in, overriding the methods + in the base class. ''' def getContext(self, client, classname, request): + # construct the TemplatingUtils class + utils = TemplatingUtils + if hasattr(client.instance.interfaces, 'TemplatingUtils'): + class utils(client.instance.interfaces.TemplatingUtils, utils): + pass + c = { 'options': {}, 'nothing': None, @@ -139,7 +150,7 @@ class RoundupPageTemplate(PageTemplate.PageTemplate): 'db': HTMLDatabase(client), 'config': client.instance.config, 'tracker': client.instance, - 'utils': TemplatingUtils(client), + 'utils': utils(client), 'templates': Templates(client.instance.config.TEMPLATES), } # add in the item if there is one diff --git a/roundup/templates/classic/interfaces.py b/roundup/templates/classic/interfaces.py index 40f944b..82fd85f 100644 --- a/roundup/templates/classic/interfaces.py +++ b/roundup/templates/classic/interfaces.py @@ -15,7 +15,7 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -# $Id: interfaces.py,v 1.15 2002-09-09 23:55:19 richard Exp $ +# $Id: interfaces.py,v 1.16 2002-10-11 01:26:43 richard Exp $ from roundup import mailgw from roundup.cgi import client @@ -26,6 +26,12 @@ class Client(client.Client): ''' pass +class TemplatingUtils: + ''' Methods implemented on this class will be available to HTML templates + through the 'utils' variable. + ''' + pass + class MailGW(mailgw.MailGW): ''' derives basic mail gateway implementation from the standard module, with any specific extensions diff --git a/roundup/templates/minimal/interfaces.py b/roundup/templates/minimal/interfaces.py index aab9e40..489699a 100644 --- a/roundup/templates/minimal/interfaces.py +++ b/roundup/templates/minimal/interfaces.py @@ -15,7 +15,7 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -# $Id: interfaces.py,v 1.1 2002-09-26 04:15:07 richard Exp $ +# $Id: interfaces.py,v 1.2 2002-10-11 01:26:43 richard Exp $ from roundup import mailgw from roundup.cgi import client @@ -26,6 +26,12 @@ class Client(client.Client): ''' pass +class TemplatingUtils: + ''' Methods implemented on this class will be available to HTML templates + through the 'utils' variable. + ''' + pass + class MailGW(mailgw.MailGW): ''' derives basic mail gateway implementation from the standard module, with any specific extensions -- 2.30.2