def _unpick_search(sort, allowed_fields=None, total=None):
 sorts = []
 split_sort = sort.split(',')
 for part in split_sort:
  split_part = part.strip().split()
  field = split_part[0]
  if (len(split_part) > 1):
   order = split_part[1].lower()
  else:
   order = 'asc'
  if allowed_fields:
   if (field not in allowed_fields):
    raise ValidationError(('Cannot sort by field `%s`' % field))
  if (order not in ['asc', 'desc']):
   raise ValidationError(('Invalid sort direction `%s`' % order))
  sorts.append((field, order))
 if (total and (len(sorts) > total)):
  raise ValidationError(('Too many sort criteria provided only %s allowed' % total))
 return sorts

def _unpick_search ( sort , allowed_fields = None , total = None ) : sorts = [ ] split_sort = sort . split ( ',' ) for part in split_sort : split_part = part . strip ( ) . split ( ) field = split_part [ 0 ] if ( len ( split_part ) > 1 ) : order = split_part [ 1 ] . lower ( ) else : order = 'asc' if allowed_fields : if ( field not in allowed_fields ) : raise ValidationError ( ( 'Cannot sort by field `%s`' % field ) ) if ( order not in [ 'asc' , 'desc' ] ) : raise ValidationError ( ( 'Invalid sort direction `%s`' % order ) ) sorts . append ( ( field , order ) ) if ( total and ( len ( sorts ) > total ) ) : raise ValidationError ( ( 'Too many sort criteria provided only %s allowed' % total ) ) return sorts
this is a helper function that takes a sort string eg name asc .