Permalink
Browse files

Specifying page size for articles in NewsFeed model.

  • Loading branch information...
1 parent 2d557fa commit 5dfe87fca5007b7f9a0a01bccd728dd5858e0182 @etianen committed Apr 13, 2012
@@ -29,6 +29,13 @@ class NewsFeed(ContentBase):
blank = True
)
+ per_page = models.IntegerField(
+ "articles per page",
+ default = 5,
+ blank = True,
+ null = True,
+ )
+
def get_default_news_feed():
"""Returns the default news feed for the site."""
@@ -5,7 +5,6 @@
{% block content_primary %}
{{block.super}}
-
{% article_list article_list %}
{% endblock %}
@@ -1,16 +1,17 @@
{% load pagination news %}
-{% paginate article_list per_page=5 as article_page %}
-{% if article_page.object_list %}
+{% if article_list %}
<ul class="news-article-list">
- {% for article in article_page.object_list %}
+ {% for article in article_list %}
<li>
{% article_list_item article %}
</li>
{% endfor %}
</ul>
- {% pagination article_page %}
+ {% if page_obj %}
+ {% pagination page_obj %}
+ {% endif %}
{% else %}
<p><em>There are not articles to display.</em>
@@ -12,10 +12,12 @@ def article_list(context, article_list):
"""Renders a list of news articles."""
request = context["request"]
pages = context["pages"]
+ page_obj = context.get("page_obj")
return {
"article_list": article_list,
"request": request,
"pages": pages,
+ "page_obj": page_obj,
}
@@ -21,6 +21,10 @@ class ArticleListMixin(object):
context_object_name = "article_list"
+ def get_paginate_by(self, queryset):
+ """Returns the number of articles to show per page."""
+ return self.request.pages.current.content.per_page
+
def get_context_data(self, **kwargs):
"""Returns the context data for the view."""
context = super(ArticleListMixin, self).get_context_data(**kwargs)

0 comments on commit 5dfe87f

Please sign in to comment.