comparison news/views.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 e2c3d7ecfa30
children 5ba2508939f7
comparison
equal deleted inserted replaced
1000:abd4c02aefdb 1001:c6c3ba5cf6eb
40 ####################################################################### 40 #######################################################################
41 41
42 def index(request): 42 def index(request):
43 # Defer the tags field because we are going to get all the 43 # Defer the tags field because we are going to get all the
44 # tags out in 1 query later... 44 # tags out in 1 query later...
45 stories = Story.objects.all().defer('tags').select_related() 45 stories = Story.objects.all().defer('tags').select_related(
46 'submitter', 'category', 'forums_topic')
46 paginator = create_paginator(stories) 47 paginator = create_paginator(stories)
47 48
48 page = get_page(request.GET) 49 page = get_page(request.GET)
49 try: 50 try:
50 the_page = paginator.page(page) 51 the_page = paginator.page(page)
73 74
74 ####################################################################### 75 #######################################################################
75 76
76 def archive(request, year, month): 77 def archive(request, year, month):
77 stories = Story.objects.defer('tags').filter(date_submitted__year=year, 78 stories = Story.objects.defer('tags').filter(date_submitted__year=year,
78 date_submitted__month=month).select_related() 79 date_submitted__month=month).select_related(
80 'submitter', 'category', 'forums_topic')
79 paginator = create_paginator(stories) 81 paginator = create_paginator(stories)
80 page = get_page(request.GET) 82 page = get_page(request.GET)
81 try: 83 try:
82 the_page = paginator.page(page) 84 the_page = paginator.page(page)
83 except InvalidPage: 85 except InvalidPage:
108 110
109 ####################################################################### 111 #######################################################################
110 112
111 def category(request, slug): 113 def category(request, slug):
112 category = get_object_or_404(Category, slug=slug) 114 category = get_object_or_404(Category, slug=slug)
113 stories = Story.objects.defer('tags').filter(category=category).select_related() 115 stories = Story.objects.defer('tags').filter(category=category).select_related(
116 'submitter', 'category', 'forums_topic')
114 paginator = create_paginator(stories) 117 paginator = create_paginator(stories)
115 page = get_page(request.GET) 118 page = get_page(request.GET)
116 try: 119 try:
117 the_page = paginator.page(page) 120 the_page = paginator.page(page)
118 except InvalidPage: 121 except InvalidPage:
127 context_instance = RequestContext(request)) 130 context_instance = RequestContext(request))
128 131
129 ####################################################################### 132 #######################################################################
130 133
131 def story(request, story_id): 134 def story(request, story_id):
132 story = get_object_or_404(Story, pk=story_id) 135 story = get_object_or_404(Story.objects.select_related(
136 'submitter', 'category', 'forums_topic'), pk=story_id)
133 return render_to_response('news/story.html', { 137 return render_to_response('news/story.html', {
134 'story': story, 138 'story': story,
135 }, 139 },
136 context_instance=RequestContext(request)) 140 context_instance=RequestContext(request))
137 141
172 ####################################################################### 176 #######################################################################
173 177
174 def tag(request, tag_name): 178 def tag(request, tag_name):
175 tag = get_object_or_404(Tag, name=tag_name) 179 tag = get_object_or_404(Tag, name=tag_name)
176 stories = TaggedItem.objects.get_by_model( 180 stories = TaggedItem.objects.get_by_model(
177 Story.objects.defer('tags').select_related(), tag) 181 Story.objects.defer('tags').select_related(
182 'submitter', 'category', 'forums_topic'), tag)
178 paginator = create_paginator(stories) 183 paginator = create_paginator(stories)
179 page = get_page(request.GET) 184 page = get_page(request.GET)
180 try: 185 try:
181 the_page = paginator.page(page) 186 the_page = paginator.page(page)
182 except InvalidPage: 187 except InvalidPage: