Edgewall Software

Ticket #4715: sort_reports_on_enums011.diff

File sort_reports_on_enums011.diff, 1.4 KB (added by vnaum@…, 4 years ago)

fixes enum sorting for "click on table header" sorts, patch against trac-0.11b1 (SVN revision 6673)

  • report.py

     
    303303 
    304304            if col == sort_col: 
    305305                header['asc'] = asc 
     306                 
     307                # this dict will have enum values for sorting 
     308                # and will be used in sortkey(), if non-empty: 
     309                sortValues = {} 
     310                if sort_col in ['status', 'resolution', 'priority', 'severity']: 
     311                    # must fetch sort values for that columns 
     312                    # instead of comparing them as strings 
     313                    if not db: 
     314                        db = self.env.get_db_cnx() 
     315                    cursor = db.cursor() 
     316                    cursor.execute("SELECT name," + db.cast('value', 'int') + " FROM enum WHERE type=%s", 
     317                                  (sort_col,)) 
     318                    for name, value in cursor: 
     319                        sortValues[name] = value 
     320 
    306321                def sortkey(row): 
    307322                    val = row[idx] 
     323                    # check if we have sortValues, if we do - use them as sort keys. 
     324                    if sortValues: 
     325                        return sortValues.get(val) 
     326                    # otherwise, continue with string comparison: 
    308327                    if isinstance(val, basestring): 
    309328                        val = val.lower() 
    310329                    return val