Edgewall Software

Ticket #9209: cleanup_ticket-model-py.3.patch

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

patch for trac/ticket/model.py - 2nd update to adjust for changes in other patch: 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: 
     
    164164                return field[0].get('value', '') 
    165165        except KeyError: 
    166166            pass 
    167          
     167 
    168168    def populate(self, values): 
    169169        """Populate the ticket with 'suitable' values from a dictionary""" 
    170170        field_names = [f['name'] for f in self.fields] 
     
    179179 
    180180    def insert(self, when=None, db=None): 
    181181        """Add ticket to database. 
    182          
     182 
    183183        The `db` argument is deprecated in favor of `with_transaction()`. 
    184184        """ 
    185185        assert not self.exists, 'Cannot insert an existing ticket' 
     
    214214        for field in self.time_fields: 
    215215            if field in values: 
    216216                values[field] = to_utimestamp(values[field]) 
    217          
     217 
    218218        # Insert ticket record 
    219219        tkt_id = [None] 
    220220        @self.env.with_transaction(db) 
     
    246246        Store ticket changes in the database. The ticket must already exist in 
    247247        the database.  Returns False if there were no changes to save, True 
    248248        otherwise. 
    249          
     249 
    250250        The `db` argument is deprecated in favor of `with_transaction()`. 
    251251        """ 
    252252        assert self.exists, 'Cannot update a new ticket' 
     
    337337                    VALUES (%s, %s, %s, %s, %s, %s) 
    338338                    """, (self.id, when_ts, author, name, self._old[name], 
    339339                          self[name])) 
    340              
     340 
    341341            # always save comment, even if empty  
    342342            # (numbering support for timeline) 
    343343            cursor.execute(""" 
     
    345345                    (ticket,time,author,field,oldvalue,newvalue) 
    346346                VALUES (%s,%s,%s,'comment',%s,%s) 
    347347                """, (self.id, when_ts, author, comment_num, comment)) 
    348      
     348 
    349349            cursor.execute("UPDATE ticket SET changetime=%s WHERE id=%s", 
    350350                           (when_ts, self.id)) 
    351351 
     
    384384        else: 
    385385            cursor.execute(""" 
    386386                SELECT time,author,field,oldvalue,newvalue, 1 AS permanent 
    387                 FROM ticket_change WHERE ticket=%s 
     387                FROM ticket_change WHERE ticket=%s  
    388388                  UNION  
    389389                SELECT time,author,'attachment',null,filename, 0 AS permanent 
    390390                FROM attachment WHERE id=%s  
     
    401401 
    402402    def delete(self, db=None): 
    403403        """Delete the ticket. 
    404          
     404 
    405405        The `db` argument is deprecated in favor of `with_transaction()`. 
    406406        """ 
    407407        @self.env.with_transaction(db) 
     
    444444            if not row: 
    445445                return 
    446446            ts = row[0] 
    447              
     447 
    448448            # Find modified fields and their previous value 
    449449            cursor.execute(""" 
    450450                SELECT field, oldvalue, newvalue FROM ticket_change 
     
    479479                        cursor.execute(""" 
    480480                            UPDATE ticket SET %s=%%s WHERE id=%%s 
    481481                            """ % field, (oldvalue, self.id)) 
    482              
     482 
    483483            # Delete the change 
    484484            cursor.execute(""" 
    485485                DELETE FROM ticket_change WHERE ticket=%s AND time=%s 
    486486                """, (self.id, ts)) 
    487              
     487 
    488488            # Fix the last modification time 
    489489            cursor.execute(""" 
    490490                UPDATE ticket SET changetime=( 
     
    492492                    ORDER BY time DESC LIMIT 1) 
    493493                WHERE id=%s 
    494494                """, (self.id, self.id)) 
    495          
     495 
    496496        self._fetch_ticket(self.id) 
    497497 
    498498    def modify_comment(self, cdate, author, comment, when=None): 
     
    517517                break 
    518518            if comment == (old_comment or ''): 
    519519                return 
    520          
     520 
    521521            # Comment history is stored in fields named "_comment%d" 
    522522            # Find the next edit number 
    523523            cursor.execute(""" 
     
    594594                              '%' + db.like_escape('.' + scnum))) 
    595595        for row in cursor: 
    596596            return row 
    597          
     597 
    598598        # Fallback when comment number is not available in oldvalue 
    599599        num = 0 
    600600        cursor.execute(""" 
     
    619619                break 
    620620        else: 
    621621            return 
    622          
     622 
    623623        # Find author if NULL 
    624624        if author is None: 
    625625            cursor.execute(""" 
     
    631631                break 
    632632        return (ts, author, comment) 
    633633 
    634  
    635634def simplify_whitespace(name): 
    636635    """Strip spaces and remove duplicate spaces within names""" 
    637636    if name: 
     
    668667 
    669668    def delete(self, db=None): 
    670669        """Delete the enum value. 
    671          
     670 
    672671        The `db` argument is deprecated in favor of `with_transaction()`. 
    673672        """ 
    674673        assert self.exists, 'Cannot delete non-existent %s' % self.type 
     
    694693 
    695694    def insert(self, db=None): 
    696695        """Add a new enum value. 
    697          
     696 
    698697        The `db` argument is deprecated in favor of `with_transaction()`. 
    699698        """ 
    700699        assert not self.exists, 'Cannot insert existing %s' % self.type 
     
    721720 
    722721    def update(self, db=None): 
    723722        """Update the enum value. 
    724          
     723 
    725724        The `db` argument is deprecated in favor of `with_transaction()`. 
    726725        """ 
    727726        assert self.exists, 'Cannot update non-existent %s' % self.type 
     
    793792 
    794793 
    795794class Component(object): 
    796  
    797795    def __init__(self, env, name=None, db=None): 
    798796        self.env = env 
    799797        name = simplify_whitespace(name) 
     
    820818 
    821819    def delete(self, db=None): 
    822820        """Delete the component. 
    823          
     821 
    824822        The `db` argument is deprecated in favor of `with_transaction()`. 
    825823        """ 
    826824        assert self.exists, 'Cannot delete non-existent component' 
     
    835833 
    836834    def insert(self, db=None): 
    837835        """Insert a new component. 
    838          
     836 
    839837        The `db` argument is deprecated in favor of `with_transaction()`. 
    840838        """ 
    841839        assert not self.exists, 'Cannot insert existing component' 
     
    856854 
    857855    def update(self, db=None): 
    858856        """Update the component. 
    859          
     857 
    860858        The `db` argument is deprecated in favor of `with_transaction()`. 
    861859        """ 
    862860        assert self.exists, 'Cannot update non-existent component' 
     
    897895 
    898896 
    899897class Milestone(object): 
    900  
    901898    def __init__(self, env, name=None, db=None): 
    902899        self.env = env 
    903900        name = simplify_whitespace(name) 
     
    947944 
    948945    def delete(self, retarget_to=None, author=None, db=None): 
    949946        """Delete the milestone. 
    950          
     947 
    951948        The `db` argument is deprecated in favor of `with_transaction()`. 
    952949        """ 
    953950        @self.env.with_transaction(db) 
     
    974971 
    975972    def insert(self, db=None): 
    976973        """Insert a new milestone. 
    977          
     974 
    978975        The `db` argument is deprecated in favor of `with_transaction()`. 
    979976        """ 
    980977        self.name = simplify_whitespace(self.name) 
     
    998995 
    999996    def update(self, db=None): 
    1000997        """Update the milestone. 
    1001          
     998 
    1002999        The `db` argument is deprecated in favor of `with_transaction()`. 
    10031000        """ 
    10041001        self.name = simplify_whitespace(self.name) 
     
    10661063 
    10671064 
    10681065class Version(object): 
    1069  
    10701066    def __init__(self, env, name=None, db=None): 
    10711067        self.env = env 
    10721068        name = simplify_whitespace(name) 
     
    10931089 
    10941090    def delete(self, db=None): 
    10951091        """Delete the version. 
    1096          
     1092 
    10971093        The `db` argument is deprecated in favor of `with_transaction()`. 
    10981094        """ 
    10991095        assert self.exists, 'Cannot delete non-existent version' 
     
    11081104 
    11091105    def insert(self, db=None): 
    11101106        """Insert a new version. 
    1111          
     1107 
    11121108        The `db` argument is deprecated in favor of `with_transaction()`. 
    11131109        """ 
    11141110        assert not self.exists, 'Cannot insert existing version' 
     
    11281124 
    11291125    def update(self, db=None): 
    11301126        """Update the version. 
    1131          
     1127 
    11321128        The `db` argument is deprecated in favor of `with_transaction()`. 
    11331129        """ 
    11341130        assert self.exists, 'Cannot update non-existent version'