# HG changeset patch # User Brian Neal # Date 1252871911 0 # Node ID 96eec1ed0fd3f114d5ad80405c01bd267785e1d3 # Parent 93d9e74a471ef60eb951b82d96ce78c4c4c829fc Render the forum page navigation in the view with render_to_string() to avoid doing it twice in the template code. Also undo a mistake in the last commit. Need 2 different orderings for Post objects: by creation date in normal views, and by reverse creation date in the admin. diff -r 93d9e74a471e -r 96eec1ed0fd3 gpp/forums/admin.py --- a/gpp/forums/admin.py Sun Sep 13 18:43:08 2009 +0000 +++ b/gpp/forums/admin.py Sun Sep 13 19:58:31 2009 +0000 @@ -39,6 +39,7 @@ search_fields = ('body', ) date_hierarchy = 'creation_date' list_filter = ('creation_date', 'update_date', ) + ordering = ('-creation_date', ) save_on_top = True diff -r 93d9e74a471e -r 96eec1ed0fd3 gpp/forums/models.py --- a/gpp/forums/models.py Sun Sep 13 18:43:08 2009 +0000 +++ b/gpp/forums/models.py Sun Sep 13 19:58:31 2009 +0000 @@ -119,7 +119,7 @@ user_ip = models.IPAddressField(blank=True, default='', null=True) class Meta: - ordering = ('-creation_date', ) + ordering = ('creation_date', ) @models.permalink def get_absolute_url(self): diff -r 93d9e74a471e -r 96eec1ed0fd3 gpp/forums/views.py --- a/gpp/forums/views.py Sun Sep 13 18:43:08 2009 +0000 +++ b/gpp/forums/views.py Sun Sep 13 19:58:31 2009 +0000 @@ -10,6 +10,7 @@ from django.core.paginator import InvalidPage from django.shortcuts import get_object_or_404 from django.shortcuts import render_to_response +from django.template.loader import render_to_string from django.template import RequestContext from django.views.decorators.http import require_POST @@ -67,10 +68,14 @@ page = paginator.page(page_num) except InvalidPage: raise Http404 + + # we do this for the template since it is rendered twice + page_nav = render_to_string('forums/pagination.html', {'page': page}) return render_to_response('forums/forum_index.html', { 'forum': forum, 'page': page, + 'page_nav': page_nav, }, context_instance=RequestContext(request)) @@ -93,10 +98,14 @@ last_page = page_num == paginator.num_pages + # we do this for the template since it is rendered twice + page_nav = render_to_string('forums/pagination.html', {'page': page}) + return render_to_response('forums/topic.html', { 'forum': topic.forum, 'topic': topic, 'page': page, + 'page_nav': page_nav, 'last_page': last_page, 'form': PostForm(initial={'topic_id': topic.id}), }, diff -r 93d9e74a471e -r 96eec1ed0fd3 gpp/templates/forums/forum_index.html --- a/gpp/templates/forums/forum_index.html Sun Sep 13 18:43:08 2009 +0000 +++ b/gpp/templates/forums/forum_index.html Sun Sep 13 19:58:31 2009 +0000 @@ -11,7 +11,7 @@
New Topic -{% forum_page_navigation page %} +{{ page_nav }} @@ -42,6 +42,6 @@ {% endfor %}
-{% forum_page_navigation page %} +{{ page_nav }}
{% endblock %} diff -r 93d9e74a471e -r 96eec1ed0fd3 gpp/templates/forums/topic.html --- a/gpp/templates/forums/topic.html Sun Sep 13 18:43:08 2009 +0000 +++ b/gpp/templates/forums/topic.html Sun Sep 13 19:58:31 2009 +0000 @@ -1,5 +1,4 @@ {% extends 'base.html' %} -{% load forum_tags %} {% block title %}Forums: {{ topic.name }}{% endblock %} {% block custom_js %}{% if last_page %}{{ form.media }}{% endif %}{% endblock %} {% block content %} @@ -18,14 +17,14 @@ New Reply • {% endif %} New Topic -{% forum_page_navigation page %} +{{ page_nav }} {% for post in page.object_list %} {% include 'forums/display_post.html' %} {% endfor %}
-{% forum_page_navigation page %} +{{ page_nav }} {% if last_page and user.is_authenticated %}