nodes: 0, module; 1, function_definition; 2, function_name:set_sort; 3, parameters; 4, block; 5, identifier:self; 6, identifier:request; 7, expression_statement; 8, comment:# Look for 'sort' in get request. If not available use default.; 9, expression_statement; 10, if_statement; 11, comment:# Invalid sort requests fail silently; 12, if_statement; 13, return_statement; 14, comment:"""
          Take the sort parameter from the get parameters and split it into
          the field and the prefix
          """; 15, assignment; 16, call; 17, block; 18, else_clause; 19, not_operator; 20, block; 21, tuple; 22, identifier:sort_request; 23, call; 24, attribute; 25, argument_list; 26, expression_statement; 27, expression_statement; 28, block; 29, comparison_operator:sort_field in self._allowed_sort_fields; 30, expression_statement; 31, expression_statement; 32, identifier:sort_order; 33, identifier:sort_field; 34, attribute; 35, argument_list; 36, identifier:sort_request; 37, identifier:startswith; 38, string; 39, assignment; 40, assignment; 41, expression_statement; 42, expression_statement; 43, identifier:sort_field; 44, attribute; 45, assignment; 46, assignment; 47, attribute; 48, identifier:get; 49, attribute; 50, attribute; 51, string_content:-; 52, identifier:sort_order; 53, string; 54, identifier:sort_field; 55, subscript; 56, assignment; 57, assignment; 58, identifier:self; 59, identifier:_allowed_sort_fields; 60, identifier:sort_order; 61, attribute; 62, identifier:sort_field; 63, attribute; 64, identifier:request; 65, identifier:GET; 66, identifier:self; 67, identifier:sort_parameter; 68, identifier:self; 69, identifier:default_sort; 70, string_content:-; 71, call; 72, integer:1; 73, identifier:sort_order; 74, string; 75, identifier:sort_field; 76, identifier:sort_request; 77, identifier:self; 78, identifier:default_sort_order; 79, identifier:self; 80, identifier:default_sort_field; 81, attribute; 82, argument_list; 83, identifier:sort_request; 84, identifier:split; 85, string; 86, string_content:-
code: def set_sort(self, request):
          """
          Take the sort parameter from the get parameters and split it into
          the field and the prefix
          """
          # Look for 'sort' in get request. If not available use default.
          sort_request = request.GET.get(self.sort_parameter, self.default_sort)
          if sort_request.startswith('-'):
              sort_order = '-'
              sort_field = sort_request.split('-')[1]
          else:
              sort_order = ''
              sort_field = sort_request
          # Invalid sort requests fail silently
          if not sort_field in self._allowed_sort_fields:
              sort_order = self.default_sort_order
              sort_field = self.default_sort_field
          return (sort_order, sort_field)