nodes: 0, module; 1, function_definition; 2, function_name:prepare_sorting_fields; 3, parameters; 4, block; 5, identifier:self; 6, expression_statement; 7, if_statement; 8, if_statement; 9, comment:"""
          Determine sorting direction and sorting field based on request query parameters and sorting options
          of self
          """; 10, comparison_operator:self.sorting_parameter_name in self.request.query_params; 11, comment:# Extract sorting parameter from query string; 12, block; 13, attribute; 14, comment:# Create a list of sorting parameters. Each parameter is a tuple: (field:str, descending:bool); 15, block; 16, attribute; 17, attribute; 18, expression_statement; 19, identifier:self; 20, identifier:_sorting_fields; 21, expression_statement; 22, identifier:self; 23, identifier:sorting_parameter_name; 24, attribute; 25, identifier:query_params; 26, assignment; 27, assignment; 28, identifier:self; 29, identifier:request; 30, attribute; 31, list_comprehension; 32, attribute; 33, list_comprehension; 34, identifier:self; 35, identifier:_sorting_fields; 36, call; 37, for_in_clause; 38, identifier:self; 39, identifier:_sorting_fields; 40, tuple; 41, for_in_clause; 42, attribute; 43, argument_list; 44, identifier:_; 45, call; 46, call; 47, comparison_operator:field[0] == '-'; 48, identifier:field; 49, attribute; 50, identifier:_; 51, identifier:strip; 52, attribute; 53, argument_list; 54, attribute; 55, argument_list; 56, subscript; 57, string; 58, identifier:self; 59, identifier:_sorting_fields; 60, call; 61, identifier:split; 62, string; 63, attribute; 64, identifier:get; 65, call; 66, call; 67, identifier:field; 68, integer:0; 69, string_content:-; 70, attribute; 71, argument_list; 72, string_content:,; 73, identifier:self; 74, identifier:sorting_fields_map; 75, attribute; 76, argument_list; 77, attribute; 78, argument_list; 79, attribute; 80, identifier:get; 81, attribute; 82, identifier:field; 83, identifier:lstrip; 84, string; 85, identifier:field; 86, identifier:lstrip; 87, string; 88, attribute; 89, identifier:query_params; 90, identifier:self; 91, identifier:sorting_parameter_name; 92, string_content:-; 93, string_content:-; 94, identifier:self; 95, identifier:request
code: def prepare_sorting_fields(self):
          """
          Determine sorting direction and sorting field based on request query parameters and sorting options
          of self
          """
          if self.sorting_parameter_name in self.request.query_params:
              # Extract sorting parameter from query string
              self._sorting_fields = [
                  _.strip() for _ in self.request.query_params.get(self.sorting_parameter_name).split(',')
              ]
  
          if self._sorting_fields:
              # Create a list of sorting parameters. Each parameter is a tuple: (field:str, descending:bool)
              self._sorting_fields = [
                  (self.sorting_fields_map.get(field.lstrip('-'), field.lstrip('-')), field[0] == '-')
                  for field in self._sorting_fields
              ]