nodes: 0, module; 1, function_definition; 2, function_name:init; 3, parameters; 4, block; 5, identifier:req; 6, identifier:model; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, expression_statement; 12, for_statement; 13, return_statement; 14, comment:""" Determine the sorting preference by query parameter
  
      Return an array of Sortable objects.
      """; 15, assignment; 16, assignment; 17, assignment; 18, assignment; 19, identifier:param; 20, identifier:params; 21, block; 22, identifier:params; 23, identifier:rels; 24, attribute; 25, identifier:fields; 26, attribute; 27, identifier:params; 28, boolean_operator; 29, identifier:params; 30, list_comprehension; 31, expression_statement; 32, expression_statement; 33, identifier:model; 34, identifier:relationships; 35, identifier:model; 36, identifier:all_fields; 37, call; 38, list; 39, call; 40, for_in_clause; 41, call; 42, call; 43, attribute; 44, argument_list; 45, attribute; 46, identifier:Sortable; 47, argument_list; 48, identifier:param; 49, identifier:params; 50, identifier:_validate_no_rels; 51, argument_list; 52, identifier:_validate_field; 53, argument_list; 54, identifier:req; 55, identifier:get_param_as_list; 56, string; 57, attribute; 58, identifier:SORT; 59, call; 60, identifier:param; 61, identifier:rels; 62, identifier:param; 63, identifier:fields; 64, string_content:sort; 65, identifier:goldman; 66, identifier:config; 67, attribute; 68, argument_list; 69, identifier:param; 70, identifier:lower
code: def init(req, model):
      """ Determine the sorting preference by query parameter
  
      Return an array of Sortable objects.
      """
  
      rels = model.relationships
      fields = model.all_fields
  
      params = req.get_param_as_list('sort') or [goldman.config.SORT]
      params = [Sortable(param.lower()) for param in params]
  
      for param in params:
          _validate_no_rels(param, rels)
          _validate_field(param, fields)
  
      return params