Changeset 4168

Show
Ignore:
Timestamp:
08/21/08 12:31:10 (3 months ago)
Author:
bobbysmith007
Message:

re #3579

Updating this to better support entry of floats that use comma as the decimal separator

version 0.6.9

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • timingandestimationplugin/branches/trac0.10/setup.py

    r4158 r4168  
    88      description='Plugin to make Trac support time estimation and tracking', 
    99      keywords='trac plugin estimation timetracking', 
    10       version='0.6.8', 
     10      version='0.6.9', 
    1111      url='http://www.trac-hacks.org/wiki/TimingAndEstimationPlugin', 
    1212      license='http://www.opensource.org/licenses/mit-license.php', 
  • timingandestimationplugin/branches/trac0.10/timingandestimationplugin/ticket_daemon.py

    r4158 r4168  
    2727    db.commit() 
    2828         
    29 def save_ticket_change( db, ticket_id, author, change_time, field, oldvalue, newvalue, log): 
     29     
     30DONTUPDATE = "DONTUPDATE" 
     31 
     32def save_ticket_change( db, ticket_id, author, change_time, field, oldvalue, newvalue, log, dontinsert=False): 
    3033    if type(change_time) == datetime.datetime: 
    3134        change_time = to_timestamp(change_time) 
     
    3639    cursor.execute(sql, (ticket_id, author, change_time, field)) 
    3740    if cursor.fetchone(): 
    38         cursor.execute("""UPDATE ticket_change  SET oldvalue=%s, newvalue=%s  
     41        if oldvalue == DONTUPDATE: 
     42            cursor.execute("""UPDATE ticket_change  SET  newvalue=%s  
    3943                       WHERE ticket=%s and author=%s and time=%s and field=%s""", 
    40                        (oldvalue, newvalue, ticket_id, author, change_time, field)) 
     44                           ( newvalue, ticket_id, author, change_time, field)) 
     45 
     46        else: 
     47            cursor.execute("""UPDATE ticket_change  SET oldvalue=%s, newvalue=%s  
     48                       WHERE ticket=%s and author=%s and time=%s and field=%s""", 
     49                           (oldvalue, newvalue, ticket_id, author, change_time, field)) 
    4150    else: 
    42         cursor.execute("""INSERT INTO ticket_change  (ticket,time,author,field, oldvalue, newvalue)  
     51        if oldvalue == DONTUPDATE: 
     52            oldvalue = '0' 
     53        if not dontinsert: 
     54            cursor.execute("""INSERT INTO ticket_change  (ticket,time,author,field, oldvalue, newvalue)  
    4355                        VALUES(%s, %s, %s, %s, %s, %s)""", 
    44                        (ticket_id, change_time, author, field, oldvalue, newvalue)) 
     56                           (ticket_id, change_time, author, field, oldvalue, newvalue)) 
    4557    db.commit() 
    4658 
     
    5163 
    5264    def watch_hours(self, ticket): 
     65         
    5366        def readTicketValue(name, tipe, default=0): 
    5467            if ticket.values.has_key(name):         
     
    6174                    return tipe(val[2] or default) 
    6275                return default 
    63  
    6476        #some european countries use , as the decimal separator 
    6577        convertfloat = lambda x: float(x.replace(',','.')) 
     
    6779        totalHours = readTicketValue("totalhours", convertfloat) 
    6880 
    69         if not hours == 0: 
    70             db = self.env.get_db_cnx() 
    71             ticket_id = ticket.id 
    72             cl = ticket.get_changelog() 
    73             #self.log.debug("hours: "+str(hours )); 
    74             #self.log.debug("Dir_ticket:"+str(dir(ticket))) 
    75             #self.log.debug("ticket.values:"+str(ticket.values)) 
    76             #self.log.debug("changelog:"+str(cl)) 
     81        db = self.env.get_db_cnx() 
     82        ticket_id = ticket.id 
     83        cl = ticket.get_changelog() 
     84        #self.log.debug("hours: "+str(hours )); 
     85        #self.log.debug("Dir_ticket:"+str(dir(ticket))) 
     86        #self.log.debug("ticket.values:"+str(ticket.values)) 
     87        #self.log.debug("changelog:"+str(cl)) 
    7788             
    78             if cl: 
    79                 most_recent_change = cl[-1]; 
    80                 change_time = most_recent_change[0] 
    81                 author = most_recent_change[1] 
    82             else: 
    83                 change_time = ticket.time_created 
    84                 author = ticket.values["reporter"] 
    85                 save_ticket_change( db, ticket_id, author, change_time, "hours", str(0.0), str(hours), self.log) 
    86                  
     89        savedTime = False 
     90        most_recent_change = None 
     91        if cl: 
     92            most_recent_change = cl[-1]; 
     93            change_time = most_recent_change[0] 
     94            author = most_recent_change[1] 
     95        else: 
     96            change_time = ticket.time_created 
     97            author = ticket.values["reporter"] 
     98            savedTime = True 
     99            save_ticket_change( db, ticket_id, author, change_time, "hours", str(0.0), str(hours), self.log) 
     100             
     101        estimatedhours = readTicketValue("estimatedhours", convertfloat) 
     102        self.log.debug("changelog:"+str(cl)) 
     103        self.log.debug("Estimated:"+str(estimatedhours))     
     104        db = self.env.get_db_cnx() 
     105        save_ticket_change( db, ticket_id, author, change_time, "estimatedhours", DONTUPDATE, str(hours), self.log, True) 
     106        save_custom_field_value( db, ticket.id, "estimatedhours", str(estimatedhours)) 
     107        db.commit(); 
     108 
     109        if not hours == 0:                 
    87110            newtotal = str(totalHours+hours) 
    88  
     111            if not savedTime: 
     112                save_ticket_change( db, ticket_id, author, change_time, "hours", str('0'), str(hours), self.log) 
    89113            save_ticket_change( db, ticket_id, author, change_time, "totalhours", str(totalHours), str(newtotal), self.log) 
    90114            save_custom_field_value( db, ticket_id, "hours", '0')