--- report.py.orig	2008-03-07 14:56:03.339905252 +0000
+++ report.py	2008-03-07 15:42:46.097020250 +0000
@@ -285,8 +285,30 @@
                 else:
                     asc = 1
                 req.hdf[k] = asc
+                
+                # this dict will have enum values for sorting
+                # and will be used in sortkey(), if non-empty:
+                sortValues = {}
+                if sortCol in ['status', 'resolution', 'priority', 'severity']:
+                    # must fetch sort values for that columns
+                    # instead of comparing them as strings
+                    if not db:
+                        db = self.env.get_db_cnx()
+                    cursor = db.cursor()
+                    cursor.execute("SELECT name," + db.cast('value', 'int') + " FROM enum WHERE type=%s",
+                                  (sortCol,))
+                    for name, value in cursor:
+                        sortValues[name] = value
+
                 def sortkey(row):
                     val = row[colIndex]
+                    # check if we have sortValues, if we do - use them as sort keys.
+                    if sortValues:
+                        return sortValues[val]
+                    # properly sort integer values (compare as ints, not as strings)
+                    if val.isdigit():
+                        return int(val)
+                    # otherwise, continue with string comparison:
                     if isinstance(val, basestring):
                         val = val.lower()
                     return val

