def clean_sort_param_es(request, date_sort='created'):
 sort_map = {'name': 'name_sort', 'nomination': 'latest_version.nomination_date'}
 sort = request.GET.get('sort', date_sort)
 order = request.GET.get('order', 'asc')
 if (sort not in ('name', 'created', 'nomination')):
  sort = date_sort
 sort = sort_map.get(sort, date_sort)
 if (order not in ('desc', 'asc')):
  order = 'asc'
 return (sort, order)

def clean_sort_param_es ( request , date_sort = 'created' ) : sort_map = { 'name' : 'name_sort' , 'nomination' : 'latest_version.nomination_date' } sort = request . GET . get ( 'sort' , date_sort ) order = request . GET . get ( 'order' , 'asc' ) if ( sort not in ( 'name' , 'created' , 'nomination' ) ) : sort = date_sort sort = sort_map . get ( sort , date_sort ) if ( order not in ( 'desc' , 'asc' ) ) : order = 'asc' return ( sort , order )
handles empty and invalid values for sort and sort order .