comparison gpp/forums/views.py @ 170:6f14970b103a

Implement #52 Forums RSS feeds.
author Brian Neal <bgneal@gmail.com>
date Thu, 11 Feb 2010 02:29:03 +0000
parents 7071b196ddd5
children 0fa78ef80356
comparison
equal deleted inserted replaced
169:7071b196ddd5 170:6f14970b103a
80 elif query == "unanswered": 80 elif query == "unanswered":
81 return redirect('forums-unanswered_topics') 81 return redirect('forums-unanswered_topics')
82 elif query == "mine": 82 elif query == "mine":
83 return redirect('forums-my_posts') 83 return redirect('forums-my_posts')
84 84
85 public_forums = Forum.objects.public_forums()
86 feeds = [{'name': 'All Forums', 'feed': '/feeds/forums/'}]
87
85 forums = Forum.objects.forums_for_user(request.user) 88 forums = Forum.objects.forums_for_user(request.user)
86 get_forum_unread_status(forums, request.user) 89 get_forum_unread_status(forums, request.user)
87 cats = {} 90 cats = {}
88 for forum in forums: 91 for forum in forums:
92 forum.has_feed = forum in public_forums
93 if forum.has_feed:
94 feeds.append({
95 'name': '%s Forum' % forum.name,
96 'feed': '/feeds/forums/%s/' % forum.slug,
97 })
98
89 cat = cats.setdefault(forum.category.id, { 99 cat = cats.setdefault(forum.category.id, {
90 'cat': forum.category, 100 'cat': forum.category,
91 'forums': [], 101 'forums': [],
92 }) 102 })
93 cat['forums'].append(forum) 103 cat['forums'].append(forum)
95 cmpdef = lambda a, b: cmp(a['cat'].position, b['cat'].position) 105 cmpdef = lambda a, b: cmp(a['cat'].position, b['cat'].position)
96 cats = sorted(cats.values(), cmpdef) 106 cats = sorted(cats.values(), cmpdef)
97 107
98 return render_to_response('forums/index.html', { 108 return render_to_response('forums/index.html', {
99 'cats': cats, 109 'cats': cats,
110 'feeds': feeds,
100 }, 111 },
101 context_instance=RequestContext(request)) 112 context_instance=RequestContext(request))
102 113
103 114
104 def forum_index(request, slug): 115 def forum_index(request, slug):