comparison forums/views/main.py @ 680:91de9b15b410

For Django 1.5.2: select_related's depth argument is deprecated.
author Brian Neal <bgneal@gmail.com>
date Thu, 15 Aug 2013 20:35:02 -0500
parents ee87ea74d46b
children 9e803323a0d0
comparison
equal deleted inserted replaced
679:89b240fe9297 680:91de9b15b410
1 """ 1 """
2 Views for the forums application. 2 Views for the forums application.
3
3 """ 4 """
4 import collections 5 import collections
5 import datetime 6 import datetime
6 7
7 from django.contrib.auth.decorators import login_required 8 from django.contrib.auth.decorators import login_required
167 return HttpResponseForbidden() 168 return HttpResponseForbidden()
168 169
169 topic.view_count = F('view_count') + 1 170 topic.view_count = F('view_count') + 1
170 topic.save(force_update=True) 171 topic.save(force_update=True)
171 172
172 posts = topic.posts.select_related(depth=1) 173 posts = topic.posts.select_related('user')
173 174
174 paginator = create_post_paginator(posts) 175 paginator = create_post_paginator(posts)
175 page_num = get_page_num(request) 176 page_num = get_page_num(request)
176 try: 177 try:
177 page = paginator.page(page_num) 178 page = paginator.page(page_num)
258 259
259 """ 260 """
260 topic_url = reverse('forums-topic_index', kwargs={'id': id}) 261 topic_url = reverse('forums-topic_index', kwargs={'id': id})
261 262
262 if request.user.is_authenticated(): 263 if request.user.is_authenticated():
263 topic = get_object_or_404(Topic.objects.select_related(depth=1), pk=id) 264 topic = get_object_or_404(Topic.objects.select_related('forum', 'user'), pk=id)
264 try: 265 try:
265 tlv = TopicLastVisit.objects.get(user=request.user, topic=topic) 266 tlv = TopicLastVisit.objects.get(user=request.user, topic=topic)
266 except TopicLastVisit.DoesNotExist: 267 except TopicLastVisit.DoesNotExist:
267 try: 268 try:
268 flv = ForumLastVisit.objects.get(user=request.user, 269 flv = ForumLastVisit.objects.get(user=request.user,
288 def topic_latest(request, id): 289 def topic_latest(request, id):
289 """ 290 """
290 This view shows the latest (last) post in a given topic. 291 This view shows the latest (last) post in a given topic.
291 292
292 """ 293 """
293 topic = get_object_or_404(Topic.objects.select_related(depth=1), pk=id) 294 topic = get_object_or_404(Topic.objects.select_related('forum', 'user'), pk=id)
294 295
295 if topic.last_post: 296 if topic.last_post:
296 return _goto_post(topic.last_post) 297 return _goto_post(topic.last_post)
297 298
298 raise Http404 299 raise Http404