| 631 | return self.page_size |
| 632 | |
| 633 | def get_next_link(self): |
| 634 | if not self.has_next: |
| 635 | return None |
| 636 | |
| 637 | if self.page and self.cursor and self.cursor.reverse and self.cursor.offset != 0: |
| 638 | # If we're reversing direction and we have an offset cursor |
| 639 | # then we cannot use the first position we find as a marker. |
| 640 | compare = self._get_position_from_instance(self.page[-1], self.ordering) |
| 641 | else: |
| 642 | compare = self.next_position |
| 643 | offset = 0 |
| 644 | |
| 645 | has_item_with_unique_position = False |
| 646 | for item in reversed(self.page): |
| 647 | position = self._get_position_from_instance(item, self.ordering) |
| 648 | if position != compare: |
| 649 | # The item in this position and the item following it |
| 650 | # have different positions. We can use this position as |
| 651 | # our marker. |
| 652 | has_item_with_unique_position = True |
| 653 | break |
| 654 | |
| 655 | # The item in this position has the same position as the item |
| 656 | # following it, we can't use it as a marker position, so increment |
| 657 | # the offset and keep seeking to the previous item. |
| 658 | compare = position |
| 659 | offset += 1 |
| 660 | |
| 661 | if self.page and not has_item_with_unique_position: |
| 662 | # There were no unique positions in the page. |
| 663 | if not self.has_previous: |
| 664 | # We are on the first page. |
| 665 | # Our cursor will have an offset equal to the page size, |
| 666 | # but no position to filter against yet. |
| 667 | offset = self.page_size |
| 668 | position = None |
| 669 | elif self.cursor.reverse: |
| 670 | # The change in direction will introduce a paging artifact, |
| 671 | # where we end up skipping forward a few extra items. |
| 672 | offset = 0 |
| 673 | position = self.previous_position |
| 674 | else: |
| 675 | # Use the position from the existing cursor and increment |
| 676 | # it's offset by the page size. |
| 677 | offset = self.cursor.offset + self.page_size |
| 678 | position = self.previous_position |
| 679 | |
| 680 | if not self.page: |
| 681 | position = self.next_position |
| 682 | |
| 683 | cursor = Cursor(offset=offset, reverse=False, position=position) |
| 684 | return self.encode_cursor(cursor) |
| 685 | |
| 686 | def get_previous_link(self): |
| 687 | if not self.has_previous: |