Oops, forgot to add some files. Now version 0.1 is alive and kicking.
authorfloguy <floguy@7f1efe38-554e-0410-b69d-834cb44da2d5>
Thu, 29 May 2008 05:36:20 +0000 (05:36 +0000)
committerfloguy <floguy@7f1efe38-554e-0410-b69d-834cb44da2d5>
Thu, 29 May 2008 05:36:20 +0000 (05:36 +0000)
git-svn-id: https://django-pagination.googlecode.com/svn/trunk@7 7f1efe38-554e-0410-b69d-834cb44da2d5

pagination/middleware.py [new file with mode: 0644]
pagination/registration.py [new file with mode: 0644]

diff --git a/pagination/middleware.py b/pagination/middleware.py
new file mode 100644 (file)
index 0000000..8a541fb
--- /dev/null
@@ -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 (file)
index 0000000..29edbbe
--- /dev/null
@@ -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