Mercurial > public > sg101
comparison gpp/forums/views/main.py @ 445:e9f203c5f5bb
Attempting to fix #218; update the topic last visit time with 'now' when viewing the last page of a topic, otherwise use the creation time of the last post on the page.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Wed, 08 Jun 2011 00:24:41 +0000 |
parents | 538a1bd2f1f4 |
children | 72ef6e809f79 |
comparison
equal
deleted
inserted
replaced
444:a0847158cf72 | 445:e9f203c5f5bb |
---|---|
182 | 182 |
183 profiles = UserProfile.objects.filter(user__id__in=users).select_related() | 183 profiles = UserProfile.objects.filter(user__id__in=users).select_related() |
184 profile_keys = [profile.id for profile in profiles] | 184 profile_keys = [profile.id for profile in profiles] |
185 user_profiles = dict((profile.user.id, profile) for profile in profiles) | 185 user_profiles = dict((profile.user.id, profile) for profile in profiles) |
186 | 186 |
187 last_post_on_page = None | |
187 for post in page.object_list: | 188 for post in page.object_list: |
188 post.user.user_profile = user_profiles[post.user.id] | 189 post.user.user_profile = user_profiles[post.user.id] |
189 post.attach_list = [] | 190 post.attach_list = [] |
191 last_post_on_page = post | |
190 | 192 |
191 # Attach badge ownership info to the user profiles to avoid lots | 193 # Attach badge ownership info to the user profiles to avoid lots |
192 # of database hits in the template: | 194 # of database hits in the template: |
193 bos_qs = BadgeOwnership.objects.filter( | 195 bos_qs = BadgeOwnership.objects.filter( |
194 profile__id__in=profile_keys).select_related() | 196 profile__id__in=profile_keys).select_related() |
208 for item in attachments: | 210 for item in attachments: |
209 post_dict[item.post.id].attach_list.append(item.embed) | 211 post_dict[item.post.id].attach_list.append(item.embed) |
210 | 212 |
211 last_page = page_num == paginator.num_pages | 213 last_page = page_num == paginator.num_pages |
212 | 214 |
213 if request.user.is_authenticated() and last_page: | 215 if request.user.is_authenticated(): |
214 _update_last_visit(request.user, topic) | 216 if last_page or last_post_on_page is None: |
217 visit_time = datetime.datetime.now() | |
218 else: | |
219 visit_time = last_post_on_page.creation_date | |
220 _update_last_visit(request.user, topic, visit_time) | |
215 | 221 |
216 # we do this for the template since it is rendered twice | 222 # we do this for the template since it is rendered twice |
217 page_nav = render_to_string('forums/pagination.html', {'page': page}) | 223 page_nav = render_to_string('forums/pagination.html', {'page': page}) |
218 | 224 |
219 can_moderate = _can_moderate(topic.forum, request.user) | 225 can_moderate = _can_moderate(topic.forum, request.user) |
340 post = form.save(request.user, request.META.get("REMOTE_ADDR", "")) | 346 post = form.save(request.user, request.META.get("REMOTE_ADDR", "")) |
341 post.unread = True | 347 post.unread = True |
342 post.user.user_profile = request.user.get_profile() | 348 post.user.user_profile = request.user.get_profile() |
343 post.attach_list = post.attachments.all() | 349 post.attach_list = post.attachments.all() |
344 _bump_post_count(request.user) | 350 _bump_post_count(request.user) |
345 _update_last_visit(request.user, form.topic) | |
346 | 351 |
347 return render_to_response('forums/display_post.html', { | 352 return render_to_response('forums/display_post.html', { |
348 'post': post, | 353 'post': post, |
349 'can_moderate': _can_moderate(form.topic.forum, request.user), | 354 'can_moderate': _can_moderate(form.topic.forum, request.user), |
350 'can_reply': True, | 355 'can_reply': True, |
588 | 593 |
589 # Save any attachments | 594 # Save any attachments |
590 form.attach_proc.save_attachments(post) | 595 form.attach_proc.save_attachments(post) |
591 | 596 |
592 _bump_post_count(request.user) | 597 _bump_post_count(request.user) |
593 _update_last_visit(request.user, topic) | |
594 return HttpResponseRedirect(post.get_absolute_url()) | 598 return HttpResponseRedirect(post.get_absolute_url()) |
595 else: | 599 else: |
596 quote_id = request.GET.get('quote') | 600 quote_id = request.GET.get('quote') |
597 if quote_id: | 601 if quote_id: |
598 quote_post = get_object_or_404(Post.objects.select_related(), | 602 quote_post = get_object_or_404(Post.objects.select_related(), |
1063 for topic in topics: | 1067 for topic in topics: |
1064 if topic.forum == old_forum: | 1068 if topic.forum == old_forum: |
1065 _move_topic(topic, old_forum, new_forum) | 1069 _move_topic(topic, old_forum, new_forum) |
1066 | 1070 |
1067 | 1071 |
1068 def _update_last_visit(user, topic): | 1072 def _update_last_visit(user, topic, visit_time): |
1069 """ | 1073 """ |
1070 Does the bookkeeping for the last visit status for the user to the | 1074 Does the bookkeeping for the last visit status for the user to the |
1071 topic/forum. | 1075 topic/forum. |
1072 """ | 1076 """ |
1073 now = datetime.datetime.now() | 1077 now = datetime.datetime.now() |
1082 | 1086 |
1083 if topic.update_date > flv.begin_date: | 1087 if topic.update_date > flv.begin_date: |
1084 try: | 1088 try: |
1085 tlv = TopicLastVisit.objects.get(user=user, topic=topic) | 1089 tlv = TopicLastVisit.objects.get(user=user, topic=topic) |
1086 except TopicLastVisit.DoesNotExist: | 1090 except TopicLastVisit.DoesNotExist: |
1087 tlv = TopicLastVisit(user=user, topic=topic) | 1091 tlv = TopicLastVisit(user=user, topic=topic, last_visit=datetime.datetime.min) |
1088 | 1092 |
1089 tlv.touch() | 1093 if visit_time > tlv.last_visit: |
1090 tlv.save() | 1094 tlv.last_visit = visit_time |
1095 tlv.save() | |
1091 | 1096 |
1092 | 1097 |
1093 def _split_topic_at(topic, post_id, new_forum, new_name): | 1098 def _split_topic_at(topic, post_id, new_forum, new_name): |
1094 """ | 1099 """ |
1095 This function splits the post given by post_id and all posts that come | 1100 This function splits the post given by post_id and all posts that come |