Skip to content

Commit

Permalink
Pagination (fix #313, rip performances)
Browse files Browse the repository at this point in the history
  • Loading branch information
pierre-24 committed Aug 30, 2015
1 parent b170ff6 commit 39d6aad
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
21 changes: 21 additions & 0 deletions templates/tutorialv2/includes/article_pager.part.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{% if paginate_articles %}

<ul class="pagination pagination-{{ position }} pagination-chapter">
{% if previous_article %}
<li class="prev">
<a href="{{ previous_article.get_absolute_url_online }}" class="ico-after arrow-left">
{{ previous_article.content.title }}
</a>
</li>
{% endif %}

{% if next_article %}
<li class="next">
<a href="{{ next_article.get_absolute_url_online }}" class="ico-after arrow-right" >
{{ next_article.content.title }}
</a>
</li>
{% endif %}
</ul>

{% endif %}
2 changes: 2 additions & 0 deletions templates/tutorialv2/view/content_online.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ <h2 class="subtitle" itemprop="description">

{% endif %}

{% include "tutorialv2/includes/article_pager.part.html" with content=content %}

{% include "tutorialv2/includes/warn_typo.part.html" with content=content %}

{% endblock %}
Expand Down
25 changes: 24 additions & 1 deletion zds/tutorialv2/views/views_published.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,30 @@ def get_context_data(self, **kwargs):
.filter(related_content=self.object)\
.order_by("pubdate")

# pagination:
# pagination of articles
context['paginate_articles'] = False

if self.object.type == 'ARTICLE':
# fetch all articles in order to find the previous and the next one
all_articles = \
[a for a in PublishedContent.objects.filter(content_type="ARTICLE", must_redirect=False).all()]
articles_count = len(all_articles)

try:
position = all_articles.index(self.public_content_object)
except ValueError:
pass # for an unknown reason, the article is not in the list. This should not happen
else:
context['paginate_articles'] = True
context['previous_article'] = None
context['next_article'] = None

if position > 0:
context['previous_article'] = all_articles[position - 1]
if position < articles_count - 1:
context['next_article'] = all_articles[position + 1]

# pagination of comments
make_pagination(context,
self.request,
queryset_reactions,
Expand Down

0 comments on commit 39d6aad

Please sign in to comment.