Example #1
0
    def get_paginator(self, queryset, limit):
        paginator = Paginator(queryset, per_page=limit)
        paginator.has_limit = bool(limit)

        # Cache count for paginator to prevent redundant calls between requests
        if settings.DATA_CACHE_ENABLED:
            key = cache_key('paginator', kwargs={
                'queryset': queryset
            })

            count = cache.get(key)

            if count is None:
                count = _count(queryset)
                cache.set(key, count)
        else:
            count = _count(queryset)

        paginator._count = count

        if not limit:
            # Prevent division by zero error in case count is zero
            paginator.per_page = max(count, 1)

        return paginator
Example #2
0
    def get_paginator(self, queryset, limit):
        paginator = Paginator(queryset, per_page=limit)
        paginator.has_limit = bool(limit)

        # Perform count an update paginator to prevent redundant call
        if not limit:
            count = len(queryset)
            paginator.per_page = count
            paginator._count = count

        return paginator
Example #3
0
    def get_paginator(self, queryset, limit):
        paginator = Paginator(queryset, per_page=limit)
        paginator.has_limit = bool(limit)

        # Perform count an update paginator to prevent redundant call
        if not limit:
            count = len(queryset)
            # Prevent division by zero error in case count is zero
            paginator.per_page = max(count, 1)
            paginator._count = count

        return paginator
Example #4
0
    def get_paginator(self, queryset, limit):
        paginator = Paginator(queryset, per_page=limit)
        paginator.has_limit = bool(limit)

        # Cache count for paginator to prevent redundant calls between requests
        if settings.DATA_CACHE_ENABLED:
            key = cache_key('paginator', kwargs={'queryset': queryset})

            count = cache.get(key)

            if count is None:
                count = _count(queryset)
                cache.set(key, count)
        else:
            count = _count(queryset)

        paginator._count = count

        if not limit:
            # Prevent division by zero error in case count is zero
            paginator.per_page = max(count, 1)

        return paginator