Mercurial > p > roundup > code
comparison doc/customizing.txt @ 1406:ca7dfc8bce15
fixes to time tracking customisation
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Sun, 02 Feb 2003 23:59:48 +0000 |
| parents | 8e4c3e8de96f |
| children | 8dc60d87ab42 |
comparison
equal
deleted
inserted
replaced
| 1405:2158bdbcac37 | 1406:ca7dfc8bce15 |
|---|---|
| 1 =================== | 1 =================== |
| 2 Customising Roundup | 2 Customising Roundup |
| 3 =================== | 3 =================== |
| 4 | 4 |
| 5 :Version: $Revision: 1.71 $ | 5 :Version: $Revision: 1.72 $ |
| 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:: |
| 2550 2. fake that the issue's "times" property has been edited, and then | 2550 2. fake that the issue's "times" property has been edited, and then |
| 2551 3. call the normal CGI edit action handler. | 2551 3. call the normal CGI edit action handler. |
| 2552 | 2552 |
| 2553 The code to do this is:: | 2553 The code to do this is:: |
| 2554 | 2554 |
| 2555 actions = client.Client.actions + ( | 2555 class Client(client.Client): |
| 2556 ('edit_with_timelog', 'timelogEditAction'), | 2556 ''' derives basic CGI implementation from the standard module, |
| 2557 ) | 2557 with any specific extensions |
| 2558 | 2558 ''' |
| 2559 def timelogEditAction(self): | 2559 actions = client.Client.actions + ( |
| 2560 ''' Handle the creation of a new time log entry if necessary. | 2560 ('edit_with_timelog', 'timelogEditAction'), |
| 2561 | 2561 ) |
| 2562 If we create a new entry, fake up a CGI form value for the altered | 2562 |
| 2563 "times" property of the issue being edited. | 2563 def timelogEditAction(self): |
| 2564 | 2564 ''' Handle the creation of a new time log entry if necessary. |
| 2565 Punt to the regular edit action when we're done. | 2565 |
| 2566 ''' | 2566 If we create a new entry, fake up a CGI form value for the |
| 2567 # if there's a timelog value specified, create an entry | 2567 altered "times" property of the issue being edited. |
| 2568 if self.form.has_key(':timelog') and \ | 2568 |
| 2569 self.form[':timelog'].value.strip(): | 2569 Punt to the regular edit action when we're done. |
| 2570 period = Interval(self.form[':timelog'].value) | 2570 ''' |
| 2571 # create it | 2571 # if there's a timelog value specified, create an entry |
| 2572 newid = self.db.timelog.create(period=period) | 2572 if self.form.has_key(':timelog') and \ |
| 2573 | 2573 self.form[':timelog'].value.strip(): |
| 2574 # if we're editing an existing item, get the old timelog value | 2574 period = Interval(self.form[':timelog'].value) |
| 2575 if self.nodeid: | 2575 # create it |
| 2576 l = self.db.issue.get(self.nodeid, 'times') | 2576 newid = self.db.timelog.create(period=period) |
| 2577 l.append(newid) | 2577 |
| 2578 else: | 2578 # if we're editing an existing item, get the old timelog value |
| 2579 l = [newid] | 2579 if self.nodeid: |
| 2580 | 2580 l = self.db.issue.get(self.nodeid, 'times') |
| 2581 # now make the fake CGI form values | 2581 l.append(newid) |
| 2582 for entry in l: | 2582 else: |
| 2583 self.form.list.append(MiniFieldStorage('times', entry)) | 2583 l = [newid] |
| 2584 | 2584 |
| 2585 # punt to the normal edit action | 2585 # now make the fake CGI form values |
| 2586 return self.editItemAction() | 2586 for entry in l: |
| 2587 | 2587 self.form.list.append(MiniFieldStorage('times', entry)) |
| 2588 | |
| 2589 # punt to the normal edit action | |
| 2590 return self.editItemAction() | |
| 2591 | |
| 2588 you add this code to your Client class in your tracker's ``interfaces.py`` | 2592 you add this code to your Client class in your tracker's ``interfaces.py`` |
| 2589 file. | 2593 file. Locate the section that looks like:: |
| 2594 | |
| 2595 class Client: | |
| 2596 ''' derives basic CGI implementation from the standard module, | |
| 2597 with any specific extensions | |
| 2598 ''' | |
| 2599 pass | |
| 2600 | |
| 2601 and insert this code in place of the ``pass`` statement. | |
| 2590 | 2602 |
| 2591 5. You'll also need to modify your ``issue.item`` form submit action so it | 2603 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> </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:: | |
| 2593 | 2615 |
| 2594 <tr> | 2616 <tr> |
| 2595 <td> </td> | 2617 <td> </td> |
| 2596 <td colspan=3> | 2618 <td colspan=3> |
| 2597 <tal:block tal:condition="context/id"> | 2619 <tal:block tal:condition="context/id"> |
| 2603 <input type="submit" name="submit" value="Submit New Issue"> | 2625 <input type="submit" name="submit" value="Submit New Issue"> |
| 2604 </tal:block> | 2626 </tal:block> |
| 2605 </td> | 2627 </td> |
| 2606 </tr> | 2628 </tr> |
| 2607 | 2629 |
| 2608 Note that the "context/submit" command usually handles all that for you - | 2630 The important change is setting the action to "edit_with_timelog" for |
| 2609 isn't it handy? The important change is setting the action to | 2631 edit operations (where the item exists) |
| 2610 "edit_with_timelog" for edit operations (where the item exists) | |
| 2611 | 2632 |
| 2612 6. We want to display a total of the time log times that have been accumulated | 2633 6. We want to display a total of the time log times that have been accumulated |
| 2613 for an issue. To do this, we'll need to actually write some Python code, | 2634 for an issue. To do this, we'll need to actually write some Python code, |
| 2614 since it's beyond the scope of PageTemplates to perform such calculations. | 2635 since it's beyond the scope of PageTemplates to perform such calculations. |
| 2615 We do this by adding a method to the TemplatingUtils class in our tracker | 2636 We do this by adding a method to the TemplatingUtils class in our tracker |
| 2616 ``interfaces.py`` module:: | 2637 ``interfaces.py`` module:: |
| 2617 | |
| 2618 | 2638 |
| 2619 class TemplatingUtils: | 2639 class TemplatingUtils: |
| 2620 ''' Methods implemented on this class will be available to HTML | 2640 ''' Methods implemented on this class will be available to HTML |
| 2621 templates through the 'utils' variable. | 2641 templates through the 'utils' variable. |
| 2622 ''' | 2642 ''' |
| 2627 total = Interval('') | 2647 total = Interval('') |
| 2628 for time in times: | 2648 for time in times: |
| 2629 total += time.period._value | 2649 total += time.period._value |
| 2630 return total | 2650 return total |
| 2631 | 2651 |
| 2652 Replace the ``pass`` line as we did in step 4 above with the Client class. | |
| 2632 As indicated in the docstrings, we will be able to access the | 2653 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. |
| 2634 | 2655 |
| 2635 7. Display the time log for an issue:: | 2656 7. Display the time log for an issue:: |
| 2636 | 2657 |
| 2637 <table class="otherinfo" tal:condition="context/times"> | 2658 <table class="otherinfo" tal:condition="context/times"> |
| 2638 <tr><th colspan="3" class="header">Time Log | 2659 <tr><th colspan="3" class="header">Time Log |
