def get_locales_by_visit(start_date, end_date):
 cache_key = 'locales_sorted_by_visits:{start}:{end}'.format(start=start_date, end=end_date)
 sorted_locales = cache.get(cache_key)
 if (sorted_locales is None):
  try:
   results = visitors_by_locale(start_date, end_date)
   locales_and_visits = results.items()
   sorted_locales = list(reversed(sorted(locales_and_visits, key=(lambda x: x[1]))))
   cache.add(cache_key, sorted_locales, CACHE_TIMEOUT)
  except (GoogleAPIError, Oauth2Error, OpenSSLError):
   log.exception('Something went wrong getting visitors by locale from Google Analytics. Nobody got a 500 though.')
   sorted_locales = [(l, 0) for l in settings.SUMO_LANGUAGES]
 return sorted_locales

def get_locales_by_visit ( start_date , end_date ) : cache_key = 'locales_sorted_by_visits:{start}:{end}' . format ( start = start_date , end = end_date ) sorted_locales = cache . get ( cache_key ) if ( sorted_locales is None ) : try : results = visitors_by_locale ( start_date , end_date ) locales_and_visits = results . items ( ) sorted_locales = list ( reversed ( sorted ( locales_and_visits , key = ( lambda x : x [ 1 ] ) ) ) ) cache . add ( cache_key , sorted_locales , CACHE_TIMEOUT ) except ( GoogleAPIError , Oauth2Error , OpenSSLError ) : log . exception ( 'Something went wrong getting visitors by locale from Google Analytics. Nobody got a 500 though.' ) sorted_locales = [ ( l , 0 ) for l in settings . SUMO_LANGUAGES ] return sorted_locales
get a list of tuples sorted descending by visits .