def sorter(default_sort_id, kwd):
 SortSpec = namedtuple('SortSpec', ['sort_id', 'order', 'arrow', 'exc_order'])
 sort_id = kwd.get('sort_id')
 order = kwd.get('order')
 if (sort_id == 'default'):
  sort_id = default_sort_id
 if (order == 'asc'):
  _order = sa.asc(sort_id)
 elif (order == 'desc'):
  _order = sa.desc(sort_id)
 else:
  order = 'desc'
  _order = sa.desc(sort_id)
 up_arrow = '&#x2191;'
 down_arrow = '&#x2193;'
 arrow = ' '
 if (order == 'asc'):
  arrow += down_arrow
 else:
  arrow += up_arrow
 return SortSpec(sort_id, order, arrow, _order)

def sorter ( default_sort_id , kwd ) : SortSpec = namedtuple ( 'SortSpec' , [ 'sort_id' , 'order' , 'arrow' , 'exc_order' ] ) sort_id = kwd . get ( 'sort_id' ) order = kwd . get ( 'order' ) if ( sort_id == 'default' ) : sort_id = default_sort_id if ( order == 'asc' ) : _order = sa . asc ( sort_id ) elif ( order == 'desc' ) : _order = sa . desc ( sort_id ) else : order = 'desc' _order = sa . desc ( sort_id ) up_arrow = '&#x2191;' down_arrow = '&#x2193;' arrow = ' ' if ( order == 'asc' ) : arrow += down_arrow else : arrow += up_arrow return SortSpec ( sort_id , order , arrow , _order )
initialize sorting variables .