Skip to content

Commit 9891622

Browse files
author
Richard Jones
committed
fixes to time tracking customisation
1 parent f1470e8 commit 9891622

File tree

1 file changed

+59
-38
lines changed

1 file changed

+59
-38
lines changed

doc/customizing.txt

Lines changed: 59 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Customising Roundup
33
===================
44

5-
:Version: $Revision: 1.71 $
5+
:Version: $Revision: 1.72 $
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
@@ -2552,44 +2552,66 @@ able to give a summary of the total time spent on a particular issue.
25522552

25532553
The code to do this is::
25542554

2555-
actions = client.Client.actions + (
2556-
('edit_with_timelog', 'timelogEditAction'),
2557-
)
2555+
class Client(client.Client):
2556+
''' derives basic CGI implementation from the standard module,
2557+
with any specific extensions
2558+
'''
2559+
actions = client.Client.actions + (
2560+
('edit_with_timelog', 'timelogEditAction'),
2561+
)
2562+
2563+
def timelogEditAction(self):
2564+
''' Handle the creation of a new time log entry if necessary.
2565+
2566+
If we create a new entry, fake up a CGI form value for the
2567+
altered "times" property of the issue being edited.
2568+
2569+
Punt to the regular edit action when we're done.
2570+
'''
2571+
# if there's a timelog value specified, create an entry
2572+
if self.form.has_key(':timelog') and \
2573+
self.form[':timelog'].value.strip():
2574+
period = Interval(self.form[':timelog'].value)
2575+
# create it
2576+
newid = self.db.timelog.create(period=period)
2577+
2578+
# if we're editing an existing item, get the old timelog value
2579+
if self.nodeid:
2580+
l = self.db.issue.get(self.nodeid, 'times')
2581+
l.append(newid)
2582+
else:
2583+
l = [newid]
25582584

2559-
def timelogEditAction(self):
2560-
''' Handle the creation of a new time log entry if necessary.
2585+
# now make the fake CGI form values
2586+
for entry in l:
2587+
self.form.list.append(MiniFieldStorage('times', entry))
25612588

2562-
If we create a new entry, fake up a CGI form value for the altered
2563-
"times" property of the issue being edited.
2589+
# punt to the normal edit action
2590+
return self.editItemAction()
2591+
2592+
you add this code to your Client class in your tracker's ``interfaces.py``
2593+
file. Locate the section that looks like::
25642594

2565-
Punt to the regular edit action when we're done.
2566-
'''
2567-
# if there's a timelog value specified, create an entry
2568-
if self.form.has_key(':timelog') and \
2569-
self.form[':timelog'].value.strip():
2570-
period = Interval(self.form[':timelog'].value)
2571-
# create it
2572-
newid = self.db.timelog.create(period=period)
2573-
2574-
# if we're editing an existing item, get the old timelog value
2575-
if self.nodeid:
2576-
l = self.db.issue.get(self.nodeid, 'times')
2577-
l.append(newid)
2578-
else:
2579-
l = [newid]
2580-
2581-
# now make the fake CGI form values
2582-
for entry in l:
2583-
self.form.list.append(MiniFieldStorage('times', entry))
2584-
2585-
# punt to the normal edit action
2586-
return self.editItemAction()
2595+
class Client:
2596+
''' derives basic CGI implementation from the standard module,
2597+
with any specific extensions
2598+
'''
2599+
pass
25872600

2588-
you add this code to your Client class in your tracker's ``interfaces.py``
2589-
file.
2601+
and insert this code in place of the ``pass`` statement.
25902602

25912603
5. You'll also need to modify your ``issue.item`` form submit action so it
2592-
calls the time logging action we just created::
2604+
calls the time logging action we just created. The current template will
2605+
look like this::
2606+
2607+
<tr>
2608+
<td>&nbsp;</td>
2609+
<td colspan=3 tal:content="structure context/submit">
2610+
submit button will go here
2611+
</td>
2612+
</tr>
2613+
2614+
replace it with this::
25932615

25942616
<tr>
25952617
<td>&nbsp;</td>
@@ -2605,17 +2627,15 @@ able to give a summary of the total time spent on a particular issue.
26052627
</td>
26062628
</tr>
26072629

2608-
Note that the "context/submit" command usually handles all that for you -
2609-
isn't it handy? The important change is setting the action to
2610-
"edit_with_timelog" for edit operations (where the item exists)
2630+
The important change is setting the action to "edit_with_timelog" for
2631+
edit operations (where the item exists)
26112632

26122633
6. We want to display a total of the time log times that have been accumulated
26132634
for an issue. To do this, we'll need to actually write some Python code,
26142635
since it's beyond the scope of PageTemplates to perform such calculations.
26152636
We do this by adding a method to the TemplatingUtils class in our tracker
26162637
``interfaces.py`` module::
26172638

2618-
26192639
class TemplatingUtils:
26202640
''' Methods implemented on this class will be available to HTML
26212641
templates through the 'utils' variable.
@@ -2629,8 +2649,9 @@ able to give a summary of the total time spent on a particular issue.
26292649
total += time.period._value
26302650
return total
26312651

2652+
Replace the ``pass`` line as we did in step 4 above with the Client class.
26322653
As indicated in the docstrings, we will be able to access the
2633-
``totalTimeSpent`` method via the ``utils`` variable in our templates. See
2654+
``totalTimeSpent`` method via the ``utils`` variable in our templates.
26342655

26352656
7. Display the time log for an issue::
26362657

0 commit comments

Comments
 (0)