comparison gpp/forums/views.py @ 114:535d02d1c017

Forums: Implemented unread status for topics and posts.
author Brian Neal <bgneal@gmail.com>
date Sun, 11 Oct 2009 20:27:07 +0000
parents d97ceb95ce02
children 0ce0104c7df3
comparison
equal deleted inserted replaced
113:d97ceb95ce02 114:535d02d1c017
21 from core.paginator import DiggPaginator 21 from core.paginator import DiggPaginator
22 from core.functions import email_admins 22 from core.functions import email_admins
23 from forums.models import Forum, Topic, Post, FlaggedPost, TopicLastVisit, \ 23 from forums.models import Forum, Topic, Post, FlaggedPost, TopicLastVisit, \
24 ForumLastVisit 24 ForumLastVisit
25 from forums.forms import NewTopicForm, NewPostForm, PostForm, MoveTopicForm 25 from forums.forms import NewTopicForm, NewPostForm, PostForm, MoveTopicForm
26 from forums.unread import get_forum_unread_status 26 from forums.unread import get_forum_unread_status, get_topic_unread_status, \
27 get_post_unread_status
27 28
28 ####################################################################### 29 #######################################################################
29 30
30 TOPICS_PER_PAGE = 50 31 TOPICS_PER_PAGE = 50
31 POSTS_PER_PAGE = 20 32 POSTS_PER_PAGE = 20
69 70
70 if not forum.category.can_access(request.user): 71 if not forum.category.can_access(request.user):
71 return HttpResponseForbidden() 72 return HttpResponseForbidden()
72 73
73 topics = forum.topics.select_related('user', 'last_post', 'last_post__user') 74 topics = forum.topics.select_related('user', 'last_post', 'last_post__user')
75 get_topic_unread_status(forum, topics, request.user)
76
74 paginator = create_topic_paginator(topics) 77 paginator = create_topic_paginator(topics)
75 page_num = int(request.GET.get('page', 1)) 78 page_num = int(request.GET.get('page', 1))
76 try: 79 try:
77 page = paginator.page(page_num) 80 page = paginator.page(page_num)
78 except InvalidPage: 81 except InvalidPage:
103 106
104 topic.view_count += 1 107 topic.view_count += 1
105 topic.save() 108 topic.save()
106 109
107 posts = topic.posts.select_related() 110 posts = topic.posts.select_related()
111 get_post_unread_status(topic, posts, request.user)
112
108 paginator = create_post_paginator(posts) 113 paginator = create_post_paginator(posts)
109 page_num = int(request.GET.get('page', 1)) 114 page_num = int(request.GET.get('page', 1))
110 try: 115 try:
111 page = paginator.page(page_num) 116 page = paginator.page(page_num)
112 except InvalidPage: 117 except InvalidPage:
193 if form.is_valid(): 198 if form.is_valid():
194 if not _can_post_in_topic(form.topic, request.user): 199 if not _can_post_in_topic(form.topic, request.user):
195 return HttpResponseForbidden("You don't have permission to post in this topic.") 200 return HttpResponseForbidden("You don't have permission to post in this topic.")
196 201
197 post = form.save(request.user, request.META.get("REMOTE_ADDR", "")) 202 post = form.save(request.user, request.META.get("REMOTE_ADDR", ""))
203 post.unread = True
198 _bump_post_count(request.user) 204 _bump_post_count(request.user)
199 _update_last_visit(request.user, form.topic) 205 _update_last_visit(request.user, form.topic)
200 return render_to_response('forums/display_post.html', { 206 return render_to_response('forums/display_post.html', {
201 'post': post, 207 'post': post,
202 'can_moderate': _can_moderate(form.topic.forum, request.user), 208 'can_moderate': _can_moderate(form.topic.forum, request.user),