comparison news/utils.py @ 1001:c6c3ba5cf6eb

V2 news stories use forums for comments.
author Brian Neal <bgneal@gmail.com>
date Thu, 26 Nov 2015 00:27:42 -0600
parents ee87ea74d46b
children
comparison
equal deleted inserted replaced
1000:abd4c02aefdb 1001:c6c3ba5cf6eb
26 tagged_items = TaggedItem.objects.filter(content_type=ct, 26 tagged_items = TaggedItem.objects.filter(content_type=ct,
27 object_id__in=story_ids).select_related('tag') 27 object_id__in=story_ids).select_related('tag')
28 28
29 for story in stories_dict.values(): 29 for story in stories_dict.values():
30 story.tag_list = [] 30 story.tag_list = []
31 story.comment_count = 0 31 if story.version == 0:
32 story.comment_count = 0
33 elif story.forums_topic:
34 # for convenience/consistency with old models...
35 story.comment_count = story.forums_comment_count()
32 36
33 # attach tags 37 # attach tags
34 for item in tagged_items: 38 for item in tagged_items:
35 stories_dict[item.object_id].tag_list.append(item.tag.name) 39 stories_dict[item.object_id].tag_list.append(item.tag.name)
36 40
37 # Now get all the comment counts out in one fell swoop 41 # Now get all the comment counts out in one fell swoop. This is only needed
42 # for older news stories...
38 43
39 story_ids = Comment.objects.filter(content_type=ct, 44 story_ids = [pk for pk in story_ids if stories_dict[pk].version == 0]
40 object_id__in=story_ids).values_list('object_id', flat=True)
41 45
42 # compute comment_count 46 if story_ids:
43 for story_id in story_ids: 47 story_ids = Comment.objects.filter(content_type=ct,
44 stories_dict[story_id].comment_count += 1 48 object_id__in=story_ids).values_list('object_id', flat=True)
49
50 # compute comment_count
51 for story_id in story_ids:
52 stories_dict[story_id].comment_count += 1