Mercurial > public > sg101
comparison gpp/forums/views.py @ 97:96eec1ed0fd3
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.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sun, 13 Sep 2009 19:58:31 +0000 |
parents | 4c33e266db03 |
children | d0d779dd0832 |
comparison
equal
deleted
inserted
replaced
96:93d9e74a471e | 97:96eec1ed0fd3 |
---|---|
8 from django.http import HttpResponseRedirect | 8 from django.http import HttpResponseRedirect |
9 from django.core.urlresolvers import reverse | 9 from django.core.urlresolvers import reverse |
10 from django.core.paginator import InvalidPage | 10 from django.core.paginator import InvalidPage |
11 from django.shortcuts import get_object_or_404 | 11 from django.shortcuts import get_object_or_404 |
12 from django.shortcuts import render_to_response | 12 from django.shortcuts import render_to_response |
13 from django.template.loader import render_to_string | |
13 from django.template import RequestContext | 14 from django.template import RequestContext |
14 from django.views.decorators.http import require_POST | 15 from django.views.decorators.http import require_POST |
15 | 16 |
16 from core.paginator import DiggPaginator | 17 from core.paginator import DiggPaginator |
17 from forums.models import Forum | 18 from forums.models import Forum |
65 page_num = int(request.GET.get('page', 1)) | 66 page_num = int(request.GET.get('page', 1)) |
66 try: | 67 try: |
67 page = paginator.page(page_num) | 68 page = paginator.page(page_num) |
68 except InvalidPage: | 69 except InvalidPage: |
69 raise Http404 | 70 raise Http404 |
71 | |
72 # we do this for the template since it is rendered twice | |
73 page_nav = render_to_string('forums/pagination.html', {'page': page}) | |
70 | 74 |
71 return render_to_response('forums/forum_index.html', { | 75 return render_to_response('forums/forum_index.html', { |
72 'forum': forum, | 76 'forum': forum, |
73 'page': page, | 77 'page': page, |
78 'page_nav': page_nav, | |
74 }, | 79 }, |
75 context_instance=RequestContext(request)) | 80 context_instance=RequestContext(request)) |
76 | 81 |
77 | 82 |
78 def topic_index(request, id): | 83 def topic_index(request, id): |
91 except InvalidPage: | 96 except InvalidPage: |
92 raise Http404 | 97 raise Http404 |
93 | 98 |
94 last_page = page_num == paginator.num_pages | 99 last_page = page_num == paginator.num_pages |
95 | 100 |
101 # we do this for the template since it is rendered twice | |
102 page_nav = render_to_string('forums/pagination.html', {'page': page}) | |
103 | |
96 return render_to_response('forums/topic.html', { | 104 return render_to_response('forums/topic.html', { |
97 'forum': topic.forum, | 105 'forum': topic.forum, |
98 'topic': topic, | 106 'topic': topic, |
99 'page': page, | 107 'page': page, |
108 'page_nav': page_nav, | |
100 'last_page': last_page, | 109 'last_page': last_page, |
101 'form': PostForm(initial={'topic_id': topic.id}), | 110 'form': PostForm(initial={'topic_id': topic.id}), |
102 }, | 111 }, |
103 context_instance=RequestContext(request)) | 112 context_instance=RequestContext(request)) |
104 | 113 |