diff options
author | luxagraf <sng@luxagraf.net> | 2015-11-08 19:54:58 -0500 |
---|---|---|
committer | luxagraf <sng@luxagraf.net> | 2015-11-08 19:54:58 -0500 |
commit | 76c0bf31bf4a21fcf18df8579dbb6f660c4d7437 (patch) | |
tree | 1088521913633ee867c62614b70ca0955302592e /app/utils | |
parent | a1122250e52d8773fb672ac60a458e4b7d6570fb (diff) |
Ported Bird app to CBV and modern URL structure. Also added base class
to utils module to handle my pagination scheme so I can reuse that bit
of code
Diffstat (limited to 'app/utils')
-rw-r--r-- | app/utils/__init__.py | 0 | ||||
-rw-r--r-- | app/utils/views.py | 18 |
2 files changed, 18 insertions, 0 deletions
diff --git a/app/utils/__init__.py b/app/utils/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/utils/__init__.py diff --git a/app/utils/views.py b/app/utils/views.py new file mode 100644 index 0000000..910f9b3 --- /dev/null +++ b/app/utils/views.py @@ -0,0 +1,18 @@ +from django.views.generic import ListView + + +class PaginatedListView(ListView): + """ + handles my own pagination system + """ + context_object_name = 'object_list' + + def dispatch(self, request, *args, **kwargs): + path = request.path.split('/')[1:-1] + if path[-1] == self.kwargs['page']: + path = "/".join(t for t in path[:-1]) + request.page_url = "/" + path + '/%d/' + else: + request.page_url = request.path + '%d/' + request.page = int(self.kwargs['page']) + return super(PaginatedListView, self).dispatch(request, *args, **kwargs) |