def sort_flavor_list(request, flavors):
 def get_key(flavor, sort_key):
  try:
   return getattr(flavor, sort_key)
  except AttributeError:
   LOG.warning('Could not find sort key "%s". Using the default "ram" instead.', sort_key)
   return getattr(flavor, 'ram')
 try:
  flavor_sort = getattr(settings, 'CREATE_INSTANCE_FLAVOR_SORT', {})
  sort_key = flavor_sort.get('key', 'ram')
  rev = flavor_sort.get('reverse', False)
  if (not callable(sort_key)):
   key = (lambda flavor: get_key(flavor, sort_key))
  else:
   key = sort_key
  flavor_list = [(flavor.id, ('%s' % flavor.name)) for flavor in sorted(flavors, key=key, reverse=rev)]
  return flavor_list
 except Exception:
  exceptions.handle(request, _('Unable to sort instance flavors.'))
  return []

def sort_flavor_list ( request , flavors ) : def get_key ( flavor , sort_key ) : try : return getattr ( flavor , sort_key ) except AttributeError : LOG . warning ( 'Could not find sort key "%s". Using the default "ram" instead.' , sort_key ) return getattr ( flavor , 'ram' ) try : flavor_sort = getattr ( settings , 'CREATE_INSTANCE_FLAVOR_SORT' , { } ) sort_key = flavor_sort . get ( 'key' , 'ram' ) rev = flavor_sort . get ( 'reverse' , False ) if ( not callable ( sort_key ) ) : key = ( lambda flavor : get_key ( flavor , sort_key ) ) else : key = sort_key flavor_list = [ ( flavor . id , ( '%s' % flavor . name ) ) for flavor in sorted ( flavors , key = key , reverse = rev ) ] return flavor_list except Exception : exceptions . handle ( request , _ ( 'Unable to sort instance flavors.' ) ) return [ ]
utility method to sort a list of flavors .