Skip to content

Commit

Permalink
improved pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
mmarcos committed Jul 27, 2017
1 parent 4c10862 commit 1b7a520
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
6 changes: 6 additions & 0 deletions arctic/paginator.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ def num_pages(self):
return -1
return super(IndefinitePaginator, self).num_pages

def page(self, number):
number = self.validate_number(number)
bottom = (number - 1) * self.per_page
top = bottom + self.per_page
return self._get_page(self.object_list[bottom:top], number, self)

def _get_page(self, *args, **kwargs):
return IndefinitePage(*args, **kwargs)

Expand Down
6 changes: 3 additions & 3 deletions arctic/templates/arctic/partials/pagination.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
<div class="row paginator-block">
<div class="col col-auto">
<div class="pagination-info">
{% blocktrans with start=page_obj.start_index end=page_obj.end_index count=paginator.count %}
{{ start }} &ndash; {{ end }} of {{ count }}
{% endblocktrans %}
{% with start=page_obj.start_index end=page_obj.end_index count=paginator.count %}
{{ start }} &ndash; {{ end }}{% if count != -1 %} {% trans 'of' %} {{ count }}{% endif %}
{% endwith %}
</div>
</div>
<div class="col col-auto">
Expand Down
2 changes: 1 addition & 1 deletion arctic/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,4 +253,4 @@ def __len__(self):
return self.count

def __getitem__(self, slice):
return self.get(1, 10)
return self.get(slice.start, slice.stop)
4 changes: 2 additions & 2 deletions example/countries/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def get(self, page, paginate_by):


class CountryListView(DataListView):
paginate_by = 11
paginate_by = 13
dataset = CountriesDataSet()
fields = ['name', 'capital', 'flag']
ordering_fields = ['name']
Expand All @@ -91,7 +91,7 @@ class CountryListView(DataListView):
permission_required = 'country_view'

def get_context_data(self, **kwargs):
# small hack to setup the localhost in the url of the local API
# small hack to setup the current host in the url of the local API
if not self.dataset.url_template.startswith('http'):
self.dataset.url_template = '{}://{}/{}'.format(
self.request.scheme,
Expand Down

0 comments on commit 1b7a520

Please sign in to comment.