Display the pagination on the home page at least - gotta do the same thing on other feed pages as well but this one is working nicely :)

This commit is contained in:
Danielle McLean 2017-12-15 11:55:29 +11:00
parent 2a65644813
commit f9e6f1dde3
Signed by: 00dani
GPG Key ID: 5A5D2D1AFF12EEC5
3 changed files with 82 additions and 3 deletions

View File

@ -24,6 +24,24 @@ def index(request, page):
return redirect('home:index', permanent=True)
entries = paginator.page(page or 1)
class Page:
def __init__(self, i):
self.i = i
@property
def url(self):
return reverse('home:index', kwargs={'page': self.i})
@property
def current(self):
return self.i == entries.number
entries.pages = tuple(Page(i) for i in paginator.page_range)
if entries.has_previous():
entries.prev = Page(entries.previous_page_number())
if entries.has_next():
entries.next = Page(entries.next_page_number())
return {
'user': user,
'entries': entries,

View File

@ -1,3 +1,8 @@
$sm = 576px
$md = 768px
$lg = 992px
$xl = 1200px
html
background-color $base00
@ -60,13 +65,36 @@ body
> footer
display flex
justify-content space-evenly
align-items center
margin 1rem
margin-top 0
text-align center
> p
margin-right 1rem
> p, nav
margin 0 .5rem
&:last-child
margin-right 0
margin 0
flex-wrap wrap
> nav
order -1
margin-bottom 1rem
width 100%
@media (min-width $md)
flex-wrap nowrap
> nav
order 0
margin-bottom 0
width unset
ul.pagination
margin 0
justify-content center
li.page-item
a.page-link
@extends a
.page-link
background-color $base02
border 1px solid rgba(0,0,0,.125)
.card
background-color $base02

View File

@ -66,6 +66,39 @@
<footer>
<p>all content licensed under <a rel="license" href="https://creativecommons.org/licenses/by-sa/4.0/">cc by-sa 4.0</a></p>
<nav>
<ul class="pagination">
{% if entries.prev %}
<li class="page-item">
<a class="page-link" rel="prev" href="{{ entries.prev.url }}">
<i class="fas fa-step-backward"></i><span class="sr-only">previous page</span>
</a>
</li>
{% endif %}
{% for page in entries.pages %}
{% if page.current %}
<li class="page-item active">
<span class="page-link">{{ page.i }} <span class="sr-only">(current page)</span></span>
</li>
{% else %}
<li class="page-item">
<a class="page-link" href="{{ page.url }}">{{ page.i }}</a>
</li>
{% endif %}
{% endfor %}
{% if entries.next %}
<li class="page-item">
<a class="page-link" rel="next" href="{{ entries.next.url }}">
<i class="fas fa-step-forward"></i><span class="sr-only">next page</span>
</a>
</li>
{% endif %}
</ul>
</nav>
{% get_package_json as package %}
<p>powered by <a rel="code-repository" href="{{ package.repository }}/tree/v{{ package.version }}">{{ package.name }} {{ package.version }}</a></p>
</footer>