Make sorting columns use a key function instead of cmp

This commit is contained in:
Charles Haley 2010-12-04 17:21:44 +00:00
parent 0e3a2fc39d
commit 4aab356c69

View File

@ -366,11 +366,10 @@ widgets = {
'enumeration': Enumeration 'enumeration': Enumeration
} }
def field_sort(y, z, x=None): def field_sort_key(y, x=None):
m1, m2 = x[y], x[z] m1 = x[y]
n1 = 'zzzzz' if m1['datatype'] == 'comments' else m1['name'] n1 = 'zzzzz' if m1['datatype'] == 'comments' else m1['name']
n2 = 'zzzzz' if m2['datatype'] == 'comments' else m2['name'] return sort_key(n1)
return cmp(sort_key(n1), sort_key(n2))
def populate_metadata_page(layout, db, book_id, bulk=False, two_column=False, parent=None): def populate_metadata_page(layout, db, book_id, bulk=False, two_column=False, parent=None):
def widget_factory(type, col): def widget_factory(type, col):
@ -382,7 +381,7 @@ def populate_metadata_page(layout, db, book_id, bulk=False, two_column=False, pa
return w return w
x = db.custom_column_num_map x = db.custom_column_num_map
cols = list(x) cols = list(x)
cols.sort(cmp=partial(field_sort, x=x)) cols.sort(key=partial(field_sort_key, x=x))
count_non_comment = len([c for c in cols if x[c]['datatype'] != 'comments']) count_non_comment = len([c for c in cols if x[c]['datatype'] != 'comments'])
layout.setColumnStretch(1, 10) layout.setColumnStretch(1, 10)