mirror of
				https://github.com/encode/django-rest-framework.git
				synced 2025-11-04 18:08:03 +03:00 
			
		
		
		
	Add LimitOffsetPagination.get_count to allow method override (#5846)
* Add LimitOffsetPagination.get_count to allow method override * Format method docstring
This commit is contained in:
		
							parent
							
								
									5e6abfbafe
								
							
						
					
					
						commit
						a7e2a7bfcd
					
				| 
						 | 
					@ -45,16 +45,6 @@ def _divide_with_ceil(a, b):
 | 
				
			||||||
    return a // b
 | 
					    return a // b
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def _get_count(queryset):
 | 
					 | 
				
			||||||
    """
 | 
					 | 
				
			||||||
    Determine an object count, supporting either querysets or regular lists.
 | 
					 | 
				
			||||||
    """
 | 
					 | 
				
			||||||
    try:
 | 
					 | 
				
			||||||
        return queryset.count()
 | 
					 | 
				
			||||||
    except (AttributeError, TypeError):
 | 
					 | 
				
			||||||
        return len(queryset)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
def _get_displayed_page_numbers(current, final):
 | 
					def _get_displayed_page_numbers(current, final):
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    This utility function determines a list of page numbers to display.
 | 
					    This utility function determines a list of page numbers to display.
 | 
				
			||||||
| 
						 | 
					@ -332,7 +322,7 @@ class LimitOffsetPagination(BasePagination):
 | 
				
			||||||
    template = 'rest_framework/pagination/numbers.html'
 | 
					    template = 'rest_framework/pagination/numbers.html'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def paginate_queryset(self, queryset, request, view=None):
 | 
					    def paginate_queryset(self, queryset, request, view=None):
 | 
				
			||||||
        self.count = _get_count(queryset)
 | 
					        self.count = self.get_count(queryset)
 | 
				
			||||||
        self.limit = self.get_limit(request)
 | 
					        self.limit = self.get_limit(request)
 | 
				
			||||||
        if self.limit is None:
 | 
					        if self.limit is None:
 | 
				
			||||||
            return None
 | 
					            return None
 | 
				
			||||||
| 
						 | 
					@ -468,6 +458,15 @@ class LimitOffsetPagination(BasePagination):
 | 
				
			||||||
            )
 | 
					            )
 | 
				
			||||||
        ]
 | 
					        ]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def get_count(self, queryset):
 | 
				
			||||||
 | 
					        """
 | 
				
			||||||
 | 
					        Determine an object count, supporting either querysets or regular lists.
 | 
				
			||||||
 | 
					        """
 | 
				
			||||||
 | 
					        try:
 | 
				
			||||||
 | 
					            return queryset.count()
 | 
				
			||||||
 | 
					        except (AttributeError, TypeError):
 | 
				
			||||||
 | 
					            return len(queryset)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class CursorPagination(BasePagination):
 | 
					class CursorPagination(BasePagination):
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user