Mercurial > public > sg101
comparison gpp/news/views.py @ 197:2baadae33f2e
Got autocomplete working for the member search. Updated django and ran into a bug where url tags with comma separated kwargs starting consuming tons of CPU throughput. The work-around is to cut over to using spaces between arguments. This is now allowed to be consistent with other tags. Did some query optimization for the news app.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sat, 10 Apr 2010 04:32:24 +0000 |
parents | 62eb9cbbcffc |
children | b4305e18d3af |
comparison
equal
deleted
inserted
replaced
196:893b6d462cf9 | 197:2baadae33f2e |
---|---|
38 return DiggPaginator(stories, NEWS_PER_PAGE, body=5, tail=3, margin=3, padding=2) | 38 return DiggPaginator(stories, NEWS_PER_PAGE, body=5, tail=3, margin=3, padding=2) |
39 | 39 |
40 ####################################################################### | 40 ####################################################################### |
41 | 41 |
42 def index(request, page=1): | 42 def index(request, page=1): |
43 stories = Story.objects.all() | 43 stories = Story.objects.all().select_related() |
44 paginator = create_paginator(stories) | 44 paginator = create_paginator(stories) |
45 try: | 45 try: |
46 the_page = paginator.page(int(page)) | 46 the_page = paginator.page(int(page)) |
47 except InvalidPage: | 47 except InvalidPage: |
48 raise Http404 | 48 raise Http404 |
85 context_instance = RequestContext(request)) | 85 context_instance = RequestContext(request)) |
86 | 86 |
87 ####################################################################### | 87 ####################################################################### |
88 | 88 |
89 def category_index(request): | 89 def category_index(request): |
90 categories = Category.objects.all() | 90 categories = Category.objects.all().select_related() |
91 cat_list = [] | 91 cat_list = [] |
92 for cat in categories: | 92 for cat in categories: |
93 cat_list.append((cat, cat.story_set.all()[:10])) | 93 cat_list.append((cat, cat.story_set.defer('tags')[:10])) |
94 | 94 |
95 return render_to_response('news/category_index.html', { | 95 return render_to_response('news/category_index.html', { |
96 'cat_list': cat_list, | 96 'cat_list': cat_list, |
97 'search_form': SearchNewsForm(), | 97 'search_form': SearchNewsForm(), |
98 }, | 98 }, |
213 | 213 |
214 ####################################################################### | 214 ####################################################################### |
215 | 215 |
216 def tag(request, tag_name, page=1): | 216 def tag(request, tag_name, page=1): |
217 tag = get_object_or_404(Tag, name=tag_name) | 217 tag = get_object_or_404(Tag, name=tag_name) |
218 stories = TaggedItem.objects.get_by_model(Story, tag) | 218 stories = TaggedItem.objects.get_by_model(Story.objects.all().select_related(), tag) |
219 paginator = create_paginator(stories) | 219 paginator = create_paginator(stories) |
220 try: | 220 try: |
221 the_page = paginator.page(int(page)) | 221 the_page = paginator.page(int(page)) |
222 except InvalidPage: | 222 except InvalidPage: |
223 raise Http404 | 223 raise Http404 |
225 return render_to_response('news/index.html', { | 225 return render_to_response('news/index.html', { |
226 'title': 'Stories with tag: "%s"' % tag_name, | 226 'title': 'Stories with tag: "%s"' % tag_name, |
227 'page': the_page, | 227 'page': the_page, |
228 'search_form': SearchNewsForm(), | 228 'search_form': SearchNewsForm(), |
229 }, | 229 }, |
230 context_instance = RequestContext(request)) | 230 context_instance=RequestContext(request)) |
231 | 231 |
232 ####################################################################### | 232 ####################################################################### |
233 | 233 |
234 @login_required | 234 @login_required |
235 def email_story(request, story_id): | 235 def email_story(request, story_id): |