~netlandish/django-pagination

14cf29d545144a9b5c5940aa11797b166c5a8f54 — floguy 16 years ago bad1d3d
Oops, forgot to add some files.  Now version 0.1 is alive and kicking.


git-svn-id: https://django-pagination.googlecode.com/svn/trunk@7 7f1efe38-554e-0410-b69d-834cb44da2d5
2 files changed, 33 insertions(+), 0 deletions(-)

A pagination/middleware.py
A pagination/registration.py
A pagination/middleware.py => pagination/middleware.py +6 -0
@@ 0,0 1,6 @@
class PaginationMiddleware(object):
    def process_request(self, request):
        try:
            request.page = int(request['page'])
        except KeyError:
            request.page = 1
\ No newline at end of file

A pagination/registration.py => pagination/registration.py +27 -0
@@ 0,0 1,27 @@
from django.conf import settings

default_pagination = getattr(settings, 'DEFAULT_PAGINATION', 20)

class PaginationRegistrar(object):
    _registry = {}
    
    def register(self, model, pagination=None):
        self._registry[model] = pagination or default_pagination
    
    def unregister(self, model):
        try:
            del self._registry[model]
        except KeyError:
            return
    
    def get_for_model(self, model):
        if model in self._registry:
            return self._registry[model]
        return None

def get_registry():
    registry = getattr(settings, '_pagination_registry', None)
    if registry is None:
        registry = PaginationRegistrar()
        setattr(settings, '_pagination_registry', registry)
    return registry
\ No newline at end of file