Changeset 2449

Show
Ignore:
Timestamp:
07/10/07 17:59:40 (1 year ago)
Author:
coling
Message:

WorkLogPlugin:

Complete full integration with TimingAndEstimationPlugin.
This commit adds support for automatically adding hours to the ticket based on the time spent working.
Config options control how to round the number of hours to the nearest x minutes.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • worklogplugin/0.10/worklog/manager.py

    r2448 r2449  
    11from time import time 
     2from datetime import tzinfo, timedelta, datetime 
     3from util import pretty_timedelta 
    24from trac.ticket.notification import TicketNotifyEmail 
    35from trac.ticket import Ticket 
    46from trac.ticket.web_ui import TicketModule 
     7from trac.util.datefmt import format_date, format_time 
    58 
    69class WorkLogManager: 
     
    156159                       'WHERE user=%s AND lastchange=%s AND endtime=0', 
    157160                       (stoptime, stoptime, self.authname, active['lastchange'])) 
     161 
     162        message = '' 
     163        if self.config.getbool('worklog', 'comment'): 
     164            started = datetime.fromtimestamp(active['starttime']) 
     165            finished = datetime.fromtimestamp(stoptime) 
     166            message = '%s worked on this ticket for %s between %s %s and %s %s' % \ 
     167                      (self.authname, pretty_timedelta(started, finished), \ 
     168                       format_date(active['starttime']), format_time(active['starttime']), \ 
     169                       format_date(stoptime), format_time(stoptime)) 
     170        if self.config.getbool('worklog', 'timingandestimation') and \ 
     171               self.config.get('ticket-custom', 'hours'): 
     172            if not message: 
     173                message = 'Hours recorded automatically by the worklog plugin.' 
     174 
     175            round_delta = float(self.config.getint('worklog', 'roundup') or 1) 
     176             
     177            # Get the delta in minutes 
     178            delta = float(int(stoptime) - int(active['starttime'])) / float(60) 
     179             
     180            # Round up if needed 
     181            delta = int(round((delta / round_delta) + float(0.5))) * int(round_delta) 
     182             
     183            db = self.env.get_db_cnx() 
     184            tckt = Ticket(self.env, active['ticket'], db) 
     185            tckt['hours'] = str(float(delta) / 60) 
     186            self.save_ticket(tckt, db, message) 
     187            message = '' 
     188 
     189        if message: 
     190            db = self.env.get_db_cnx() 
     191            tckt = Ticket(self.env, active['ticket'], db) 
     192            self.save_ticket(tckt, db, message) 
     193         
    158194        return True 
    159195 
  • worklogplugin/0.10/worklog/templates/webadminui.cs

    r2434 r2449  
    44  <fieldset> 
    55    <legend>Options:</legend> 
    6     <p style="font-weight: bold"> 
    7       The options below that have a line through them do not currently work!<br> 
    8       Implementations will come in time, please be patient! 
    9     </p> 
    106    <div class="field"> 
    117      <input type="checkbox" id="timingandestimation" name="timingandestimation" value="1" <?cs var:settings.timingandestimation ?>> 
    12       <label for="timingandestimation" style="text-decoration: line-through">Record time via <a href="http://www.trac-hacks.org/wiki/TimingAndEstimationPlugin">Timing and Estimation Plugin</a>?</label> 
     8      <label for="timingandestimation">Record time via <a href="http://www.trac-hacks.org/wiki/TimingAndEstimationPlugin">Timing and Estimation Plugin</a>?</label> 
    139    </div> 
    1410    <div class="field"> 
    1511      <input type="checkbox" id="comment" name="comment" value="1" <?cs var:settings.comment ?>> 
    16       <label for="comment" style="text-decoration: line-through">Automatically add a comment when you stop work on a ticket?</label> 
     12      <label for="comment">Automatically add a comment when you stop work on a ticket?</label> 
    1713    </div> 
    1814    <div class="field">