nodes: 0, module; 1, function_definition; 2, function_name:_prepare_sort_options; 3, parameters; 4, block; 5, identifier:self; 6, identifier:has_pk; 7, expression_statement; 8, expression_statement; 9, if_statement; 10, if_statement; 11, return_statement; 12, comment:"""
          Prepare sort options for _values attributes.
          If we manager sort by score after getting the result, we do not want to
          get values from the first sort call, but only from the last one, after
          converting results in zset into keys
          """; 13, assignment; 14, attribute; 15, comment:# if we asked for values, we have to use the redis 'sort'; 16, comment:# command, which is able to return other fields.; 17, block; 18, attribute; 19, block; 20, identifier:sort_options; 21, identifier:sort_options; 22, call; 23, identifier:self; 24, identifier:_values; 25, if_statement; 26, expression_statement; 27, identifier:self; 28, identifier:_sort_by_sortedset_after; 29, for_statement; 30, if_statement; 31, if_statement; 32, attribute; 33, argument_list; 34, not_operator; 35, block; 36, assignment; 37, identifier:key; 38, tuple; 39, block; 40, boolean_operator; 41, block; 42, not_operator; 43, block; 44, call; 45, identifier:_prepare_sort_options; 46, identifier:has_pk; 47, identifier:sort_options; 48, expression_statement; 49, subscript; 50, subscript; 51, string; 52, string; 53, if_statement; 54, identifier:sort_options; 55, parenthesized_expression; 56, for_statement; 57, identifier:sort_options; 58, expression_statement; 59, identifier:super; 60, argument_list; 61, assignment; 62, identifier:sort_options; 63, string; 64, subscript; 65, string; 66, string_content:get; 67, string_content:store; 68, comparison_operator:key in self._sort_by_sortedset; 69, block; 70, boolean_operator; 71, identifier:key; 72, tuple; 73, block; 74, assignment; 75, identifier:ExtendedCollectionManager; 76, identifier:self; 77, identifier:sort_options; 78, dictionary; 79, string_content:get; 80, attribute; 81, string; 82, string_content:keys; 83, identifier:key; 84, attribute; 85, delete_statement; 86, not_operator; 87, attribute; 88, string; 89, string; 90, if_statement; 91, identifier:sort_options; 92, None; 93, identifier:self; 94, identifier:_values; 95, string_content:fields; 96, identifier:self; 97, identifier:_sort_by_sortedset; 98, subscript; 99, identifier:has_pk; 100, identifier:self; 101, identifier:_want_score_value; 102, string_content:get; 103, string_content:store; 104, comparison_operator:key in sort_options; 105, block; 106, attribute; 107, identifier:key; 108, identifier:key; 109, identifier:sort_options; 110, expression_statement; 111, identifier:self; 112, identifier:_sort_by_sortedset; 113, assignment; 114, subscript; 115, call; 116, attribute; 117, identifier:key; 118, attribute; 119, argument_list; 120, identifier:self; 121, identifier:_sort_by_sortedset; 122, identifier:sort_options; 123, identifier:pop; 124, identifier:key
code: def _prepare_sort_options(self, has_pk):
          """
          Prepare sort options for _values attributes.
          If we manager sort by score after getting the result, we do not want to
          get values from the first sort call, but only from the last one, after
          converting results in zset into keys
          """
          sort_options = super(ExtendedCollectionManager, self)._prepare_sort_options(has_pk)
  
          if self._values:
              # if we asked for values, we have to use the redis 'sort'
              # command, which is able to return other fields.
              if not sort_options:
                  sort_options = {}
              sort_options['get'] = self._values['fields']['keys']
  
          if self._sort_by_sortedset_after:
              for key in ('get', 'store'):
                  if key in self._sort_by_sortedset:
                      del self._sort_by_sortedset[key]
              if sort_options and (not has_pk or self._want_score_value):
                  for key in ('get', 'store'):
                      if key in sort_options:
                          self._sort_by_sortedset[key] = sort_options.pop(key)
              if not sort_options:
                  sort_options = None
          return sort_options