Edgewall Software

Ticket #9209: cleanup_ticket-model-py.patch

File cleanup_ticket-model-py.patch, 8.2 KB (added by hoff.st@…, 2 years ago)

patch for trac/ticket/model.py: 28 insertions, 32 deletions of whitespace

  • trac/ticket/model.py

    diff --git a/trac/ticket/model.py b/trac/ticket/model.py
    a b  
    4545    # 0.11 compatibility 
    4646    time_created = property(lambda self: self.values.get('time')) 
    4747    time_changed = property(lambda self: self.values.get('changetime')) 
    48      
     48 
    4949    def __init__(self, env, tkt_id=None, db=None, version=None): 
    5050        self.env = env 
    5151        if tkt_id is not None: 
     
    159159                return field[0].get('value', '') 
    160160        except KeyError: 
    161161            pass 
    162          
     162 
    163163    def populate(self, values): 
    164164        """Populate the ticket with 'suitable' values from a dictionary""" 
    165165        field_names = [f['name'] for f in self.fields] 
     
    174174 
    175175    def insert(self, when=None, db=None): 
    176176        """Add ticket to database. 
    177          
     177 
    178178        The `db` argument is deprecated in favor of `with_transaction()`. 
    179179        """ 
    180180        assert not self.exists, 'Cannot insert an existing ticket' 
     
    199199        for field in self.time_fields: 
    200200            if field in values: 
    201201                values[field] = to_utimestamp(values[field]) 
    202          
     202 
    203203        # Insert ticket record 
    204204        tkt_id = [None] 
    205205        @self.env.with_transaction(db) 
     
    231231        Store ticket changes in the database. The ticket must already exist in 
    232232        the database.  Returns False if there were no changes to save, True 
    233233        otherwise. 
    234          
     234 
    235235        The `db` argument is deprecated in favor of `with_transaction()`. 
    236236        """ 
    237237        assert self.exists, 'Cannot update a new ticket' 
     
    322322                    VALUES (%s, %s, %s, %s, %s, %s) 
    323323                    """, (self.id, when_ts, author, name, self._old[name], 
    324324                          self[name])) 
    325              
     325 
    326326            # always save comment, even if empty  
    327327            # (numbering support for timeline) 
    328328            cursor.execute(""" 
     
    330330                    (ticket,time,author,field,oldvalue,newvalue) 
    331331                VALUES (%s,%s,%s,'comment',%s,%s) 
    332332                """, (self.id, when_ts, author, comment_num, comment)) 
    333      
     333 
    334334            cursor.execute("UPDATE ticket SET changetime=%s WHERE id=%s", 
    335335                           (when_ts, self.id)) 
    336336 
     
    369369        else: 
    370370            cursor.execute(""" 
    371371                SELECT time,author,field,oldvalue,newvalue, 1 AS permanent 
    372                 FROM ticket_change WHERE ticket=%s 
     372                FROM ticket_change WHERE ticket=%s  
    373373                  UNION  
    374374                SELECT time,author,'attachment',null,filename, 0 AS permanent 
    375375                FROM attachment WHERE id=%s  
     
    386386 
    387387    def delete(self, db=None): 
    388388        """Delete the ticket. 
    389          
     389 
    390390        The `db` argument is deprecated in favor of `with_transaction()`. 
    391391        """ 
    392392        @self.env.with_transaction(db) 
     
    429429            if not row: 
    430430                return 
    431431            ts = row[0] 
    432              
     432 
    433433            # Find modified fields and their previous value 
    434434            cursor.execute(""" 
    435435                SELECT field, oldvalue, newvalue FROM ticket_change 
     
    464464                        cursor.execute(""" 
    465465                            UPDATE ticket SET %s=%%s WHERE id=%%s 
    466466                            """ % field, (oldvalue, self.id)) 
    467              
     467 
    468468            # Delete the change 
    469469            cursor.execute(""" 
    470470                DELETE FROM ticket_change WHERE ticket=%s AND time=%s 
    471471                """, (self.id, ts)) 
    472              
     472 
    473473            # Fix the last modification time 
    474474            cursor.execute(""" 
    475475                UPDATE ticket SET changetime=( 
     
    477477                    ORDER BY time DESC LIMIT 1) 
    478478                WHERE id=%s 
    479479                """, (self.id, self.id)) 
    480          
     480 
    481481        self._fetch_ticket(self.id) 
    482482 
    483483    def modify_comment(self, cdate, author, comment, when=None): 
     
    502502                break 
    503503            if comment == (old_comment or ''): 
    504504                return 
    505          
     505 
    506506            # Comment history is stored in fields named "_comment%d" 
    507507            # Find the next edit number 
    508508            cursor.execute(""" 
     
    579579                              '%' + db.like_escape('.' + scnum))) 
    580580        for row in cursor: 
    581581            return row 
    582          
     582 
    583583        # Fallback when comment number is not available in oldvalue 
    584584        num = 0 
    585585        cursor.execute(""" 
     
    604604                break 
    605605        else: 
    606606            return 
    607          
     607 
    608608        # Find author if NULL 
    609609        if author is None: 
    610610            cursor.execute(""" 
     
    616616                break 
    617617        return (ts, author, comment) 
    618618 
    619  
    620619def simplify_whitespace(name): 
    621620    """Strip spaces and remove duplicate spaces within names""" 
    622621    if name: 
     
    653652 
    654653    def delete(self, db=None): 
    655654        """Delete the enum value. 
    656          
     655 
    657656        The `db` argument is deprecated in favor of `with_transaction()`. 
    658657        """ 
    659658        assert self.exists, 'Cannot delete non-existent %s' % self.type 
     
    679678 
    680679    def insert(self, db=None): 
    681680        """Add a new enum value. 
    682          
     681 
    683682        The `db` argument is deprecated in favor of `with_transaction()`. 
    684683        """ 
    685684        assert not self.exists, 'Cannot insert existing %s' % self.type 
     
    706705 
    707706    def update(self, db=None): 
    708707        """Update the enum value. 
    709          
     708 
    710709        The `db` argument is deprecated in favor of `with_transaction()`. 
    711710        """ 
    712711        assert self.exists, 'Cannot update non-existent %s' % self.type 
     
    778777 
    779778 
    780779class Component(object): 
    781  
    782780    def __init__(self, env, name=None, db=None): 
    783781        self.env = env 
    784782        name = simplify_whitespace(name) 
     
    805803 
    806804    def delete(self, db=None): 
    807805        """Delete the component. 
    808          
     806 
    809807        The `db` argument is deprecated in favor of `with_transaction()`. 
    810808        """ 
    811809        assert self.exists, 'Cannot delete non-existent component' 
     
    820818 
    821819    def insert(self, db=None): 
    822820        """Insert a new component. 
    823          
     821 
    824822        The `db` argument is deprecated in favor of `with_transaction()`. 
    825823        """ 
    826824        assert not self.exists, 'Cannot insert existing component' 
     
    841839 
    842840    def update(self, db=None): 
    843841        """Update the component. 
    844          
     842 
    845843        The `db` argument is deprecated in favor of `with_transaction()`. 
    846844        """ 
    847845        assert self.exists, 'Cannot update non-existent component' 
     
    882880 
    883881 
    884882class Milestone(object): 
    885  
    886883    def __init__(self, env, name=None, db=None): 
    887884        self.env = env 
    888885        name = simplify_whitespace(name) 
     
    932929 
    933930    def delete(self, retarget_to=None, author=None, db=None): 
    934931        """Delete the milestone. 
    935          
     932 
    936933        The `db` argument is deprecated in favor of `with_transaction()`. 
    937934        """ 
    938935        @self.env.with_transaction(db) 
     
    959956 
    960957    def insert(self, db=None): 
    961958        """Insert a new milestone. 
    962          
     959 
    963960        The `db` argument is deprecated in favor of `with_transaction()`. 
    964961        """ 
    965962        self.name = simplify_whitespace(self.name) 
     
    983980 
    984981    def update(self, db=None): 
    985982        """Update the milestone. 
    986          
     983 
    987984        The `db` argument is deprecated in favor of `with_transaction()`. 
    988985        """ 
    989986        self.name = simplify_whitespace(self.name) 
     
    10511048 
    10521049 
    10531050class Version(object): 
    1054  
    10551051    def __init__(self, env, name=None, db=None): 
    10561052        self.env = env 
    10571053        name = simplify_whitespace(name) 
     
    10781074 
    10791075    def delete(self, db=None): 
    10801076        """Delete the version. 
    1081          
     1077 
    10821078        The `db` argument is deprecated in favor of `with_transaction()`. 
    10831079        """ 
    10841080        assert self.exists, 'Cannot delete non-existent version' 
     
    10931089 
    10941090    def insert(self, db=None): 
    10951091        """Insert a new version. 
    1096          
     1092 
    10971093        The `db` argument is deprecated in favor of `with_transaction()`. 
    10981094        """ 
    10991095        assert not self.exists, 'Cannot insert existing version' 
     
    11131109 
    11141110    def update(self, db=None): 
    11151111        """Update the version. 
    1116          
     1112 
    11171113        The `db` argument is deprecated in favor of `with_transaction()`. 
    11181114        """ 
    11191115        assert self.exists, 'Cannot update non-existent version'