Changeset - 8f4c8a69d6f8
[Not reviewed]
0 2 0
Bradley Kuhn (bkuhn) - 9 years ago 2015-03-04 23:04:13
bkuhn@ebb.org
Rework blog's custom_index for new pagination.

The pagination support changed, and as was previously done a few commits
ago for news, I'm trying a similar solution for blogs.

In this case, I'm trying to use the existing custom_index() method we
have and adapt it to properly support pagination in the way we want.

I'm not completely sure this will work, but I think it's at least close.
2 files changed with 28 insertions and 8 deletions:
0 comments (0 inline, 0 general)
www/conservancy/apps/blog/views.py
Show inline comments
...
 
@@ -64,6 +64,24 @@ def custom_index(request, queryset, *args, **kwargs):
 
    # return object_list(request, queryset, *args, **kwargs)
 
    kwargs['queryset'] = queryset
 
    kwargs['extra_context'] = extra_context
 

	
 
    paginator = Paginator(queryset, paginate_by)
 

	
 
    page = request.GET.get('page')
 

	
 
    try:
 
        blog_entries = paginator.page(page)
 
    except PageNotAnInteger:
 
        # If page is not an integer, deliver first page.
 
        blog_entries = paginator.page(1)
 
    except EmptyPage:
 
        # If page is out of range (e.g. 9999), deliver last page of results.
 
        blog_entires = paginator.page(paginator.num_pages)
 

	
 
    return render_to_response('blog/entry_list.html',
 
                              {"blog_entries": blog_entries, "date_list" : date_list,
 
                               "authors" : authors, "tags" : tags })
 

	
 
    callable = BlogListView.as_view(**kwargs)
 
    return callable(request)
 

	
www/conservancy/templates/blog/entry_list.html
Show inline comments
...
 
@@ -12,19 +12,21 @@
 
</p>
 
{% endif %}
 

	
 
{% for object in object_list %}
 
{% for entry in blog_entries %}
 
    <div class="shaded">
 
    <p class="date">{{ object.pub_date|date:"F j, Y" }} by {{ object.author.formal_name }}</p>
 
    <h3><a href="{{ object.get_absolute_url }}">{{ object.headline|safe }}</a></h3>
 
        {{ object.body|safe }}
 
    <p class="date small">Posted by <strong>{{ object.author.formal_name}}</strong> on {{ object.pub_date|date:"F j, Y" }}</p>
 
    {% if object.tags.all %}<p class="blog-tags small">Tags: {% for tag in object.tags.all %}<a href="{{ tag.get_absolute_url }}">{{ tag.label }}</a>{% if not forloop.last %}, {% endif %}{% endfor %}</p>{% endif %}
 
    <p class="date">{{ entry.pub_date|date:"F j, Y" }} by {{ entry.author.formal_name }}</p>
 
    <h3><a href="{{ entry.get_absolute_url }}">{{ entry.headline|safe }}</a></h3>
 
        {{ entry.body|safe }}
 
    <p class="date small">Posted by <strong>{{ entry.author.formal_name}}</strong> on {{ entry.pub_date|date:"F j, Y" }}</p>
 
    {% if entry.tags.all %}<p class="blog-tags small">Tags: {% for tag in entry.tags.all %}<a href="{{ tag.get_absolute_url }}">{{ tag.label }}</a>{% if not forloop.last %}, {% endif %}{% endfor %}</p>{% endif %}
 
    </div>
 
{% endfor %}
 

	
 
<p>
 
{% if has_next %}<a class="next_page_button" href="?page={{ next }}{% if query_string %}&amp;{{ query_string|escape }}{% endif %}">Next page (older) &raquo;</a>{% endif %}
 
{% if has_previous %}<a href="?page={{ previous }}{% if query_string %}&amp;{{ query_string|escape }}{% endif %}">&laquo; Previous page (newer)</a>{% endif %}
 
{% if blog_entries.has_next %}<a class="next_page_button" href="?page={{ blog_entries.next_page_number }}{% if query_string %}&amp;{{ query_string|escape }}{% endif %}">Next page (older) &raquo;</a>{% endif %}
 
{% if blog_entries.has_previous %}<a href="?page={{ blog_entires.previous_page_number }}{% if query_string %}&amp;{{ query_string|escape }}{% endif %}">&laquo; Previous page (newer)</a>{% endif %}
 
</p>
 
<p>{% for pagenum in blog_entries.paginator.page_range %}{% ifequal pagenum blog_entries.number %}[{{ pagenum }}]{% else %}<a href="?page={{ pagenum }}">{{ pagenum }}</a>{% endifequal %} {% endfor %}
 
</p>
 
<div class="clear"></div>
 

	
0 comments (0 inline, 0 general)