nodes: 0, module; 1, function_definition; 2, function_name:remove_invalid_fields; 3, parameters; 4, block; 5, identifier:self; 6, identifier:queryset; 7, identifier:fields; 8, identifier:view; 9, expression_statement; 10, expression_statement; 11, expression_statement; 12, comment:# for each field sent down from the query param,; 13, comment:# determine if its valid or invalid; 14, for_statement; 15, return_statement; 16, comment:"""Remove invalid fields from an ordering.
  
          Overwrites the DRF default remove_invalid_fields method to return
          both the valid orderings and any invalid orderings.
          """; 17, assignment; 18, assignment; 19, identifier:term; 20, identifier:fields; 21, block; 22, expression_list; 23, identifier:valid_orderings; 24, list; 25, identifier:invalid_orderings; 26, list; 27, expression_statement; 28, comment:# add back the '-' add the end if necessary; 29, expression_statement; 30, expression_statement; 31, if_statement; 32, identifier:valid_orderings; 33, identifier:invalid_orderings; 34, assignment; 35, assignment; 36, assignment; 37, identifier:ordering; 38, block; 39, else_clause; 40, identifier:stripped_term; 41, call; 42, identifier:reverse_sort_term; 43, conditional_expression:'' if len(stripped_term) is len(term) else '-'; 44, identifier:ordering; 45, call; 46, expression_statement; 47, block; 48, attribute; 49, argument_list; 50, string; 51, comparison_operator:len(stripped_term) is len(term); 52, string; 53, attribute; 54, argument_list; 55, call; 56, expression_statement; 57, identifier:term; 58, identifier:lstrip; 59, string; 60, call; 61, call; 62, string_content:-; 63, identifier:self; 64, identifier:ordering_for; 65, identifier:stripped_term; 66, identifier:view; 67, attribute; 68, argument_list; 69, call; 70, string_content:-; 71, identifier:len; 72, argument_list; 73, identifier:len; 74, argument_list; 75, identifier:valid_orderings; 76, identifier:append; 77, binary_operator:reverse_sort_term + ordering; 78, attribute; 79, argument_list; 80, identifier:stripped_term; 81, identifier:term; 82, identifier:reverse_sort_term; 83, identifier:ordering; 84, identifier:invalid_orderings; 85, identifier:append; 86, identifier:term
code: def remove_invalid_fields(self, queryset, fields, view):
          """Remove invalid fields from an ordering.
  
          Overwrites the DRF default remove_invalid_fields method to return
          both the valid orderings and any invalid orderings.
          """
  
          valid_orderings = []
          invalid_orderings = []
  
          # for each field sent down from the query param,
          # determine if its valid or invalid
          for term in fields:
              stripped_term = term.lstrip('-')
              # add back the '-' add the end if necessary
              reverse_sort_term = '' if len(stripped_term) is len(term) else '-'
              ordering = self.ordering_for(stripped_term, view)
  
              if ordering:
                  valid_orderings.append(reverse_sort_term + ordering)
              else:
                  invalid_orderings.append(term)
  
          return valid_orderings, invalid_orderings