Edgewall Software

Ticket #4715: sort_reports_on_enums.diff

File sort_reports_on_enums.diff, 1.5 KB (added by vnaum@…, 4 years ago)

fixes enum sorting for "click on table header" sorts

  • report.py

    old new  
    285285                else: 
    286286                    asc = 1 
    287287                req.hdf[k] = asc 
     288                 
     289                # this dict will have enum values for sorting 
     290                # and will be used in sortkey(), if non-empty: 
     291                sortValues = {} 
     292                if sortCol in ['status', 'resolution', 'priority', 'severity']: 
     293                    # must fetch sort values for that columns 
     294                    # instead of comparing them as strings 
     295                    if not db: 
     296                        db = self.env.get_db_cnx() 
     297                    cursor = db.cursor() 
     298                    cursor.execute("SELECT name," + db.cast('value', 'int') + " FROM enum WHERE type=%s", 
     299                                  (sortCol,)) 
     300                    for name, value in cursor: 
     301                        sortValues[name] = value 
     302 
    288303                def sortkey(row): 
    289304                    val = row[colIndex] 
     305                    # check if we have sortValues, if we do - use them as sort keys. 
     306                    if sortValues: 
     307                        return sortValues[val] 
     308                    # properly sort integer values (compare as ints, not as strings) 
     309                    if val.isdigit(): 
     310                        return int(val) 
     311                    # otherwise, continue with string comparison: 
    290312                    if isinstance(val, basestring): 
    291313                        val = val.lower() 
    292314                    return val