From 14cf29d545144a9b5c5940aa11797b166c5a8f54 Mon Sep 17 00:00:00 2001 From: floguy Date: Thu, 29 May 2008 05:36:20 +0000 Subject: [PATCH] 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 --- pagination/middleware.py | 6 ++++++ pagination/registration.py | 27 +++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 pagination/middleware.py create mode 100644 pagination/registration.py diff --git a/pagination/middleware.py b/pagination/middleware.py new file mode 100644 index 0000000..8a541fb --- /dev/null +++ b/pagination/middleware.py @@ -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 diff --git a/pagination/registration.py b/pagination/registration.py new file mode 100644 index 0000000..29edbbe --- /dev/null +++ b/pagination/registration.py @@ -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 -- 2.20.1