Mercurial > public > sg101
comparison gpp/weblinks/views.py @ 21:884839ddbfde
Webinks: added a navigation template tag so views don't have to keep constructing the searc form. Also provided a count of search results on the template.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sun, 19 Apr 2009 21:00:06 +0000 |
parents | c0d0779b266f |
children | 62eb9cbbcffc |
comparison
equal
deleted
inserted
replaced
20:c0d0779b266f | 21:884839ddbfde |
---|---|
32 ####################################################################### | 32 ####################################################################### |
33 | 33 |
34 def link_index(request): | 34 def link_index(request): |
35 categories = Category.objects.all() | 35 categories = Category.objects.all() |
36 total_links = Link.public_objects.all().count() | 36 total_links = Link.public_objects.all().count() |
37 form = SearchForm() | |
38 return render_to_response('weblinks/index.html', { | 37 return render_to_response('weblinks/index.html', { |
39 'categories': categories, | 38 'categories': categories, |
40 'total_links': total_links, | 39 'total_links': total_links, |
41 'search_form': form, | |
42 }, | 40 }, |
43 context_instance = RequestContext(request)) | 41 context_instance = RequestContext(request)) |
44 | 42 |
45 ####################################################################### | 43 ####################################################################### |
46 | 44 |
47 def new_links(request): | 45 def new_links(request): |
48 links = Link.public_objects.order_by('-date_added')[:LINKS_PER_PAGE] | 46 links = Link.public_objects.order_by('-date_added')[:LINKS_PER_PAGE] |
49 return render_to_response('weblinks/link_summary.html', { | 47 return render_to_response('weblinks/link_summary.html', { |
50 'links': links, | 48 'links': links, |
51 'title': 'Newest Links', | 49 'title': 'Newest Links', |
52 'search_form': SearchForm(), | |
53 }, | 50 }, |
54 context_instance = RequestContext(request)) | 51 context_instance = RequestContext(request)) |
55 | 52 |
56 ####################################################################### | 53 ####################################################################### |
57 | 54 |
58 def popular_links(request): | 55 def popular_links(request): |
59 links = Link.public_objects.order_by('-hits')[:LINKS_PER_PAGE] | 56 links = Link.public_objects.order_by('-hits')[:LINKS_PER_PAGE] |
60 return render_to_response('weblinks/link_summary.html', { | 57 return render_to_response('weblinks/link_summary.html', { |
61 'links': links, | 58 'links': links, |
62 'title': 'Popular Links', | 59 'title': 'Popular Links', |
63 'search_form': SearchForm(), | |
64 }, | 60 }, |
65 context_instance = RequestContext(request)) | 61 context_instance = RequestContext(request)) |
66 | 62 |
67 ####################################################################### | 63 ####################################################################### |
68 | 64 |
82 return HttpResponseRedirect(reverse('weblinks.views.add_thanks')) | 78 return HttpResponseRedirect(reverse('weblinks.views.add_thanks')) |
83 else: | 79 else: |
84 add_form = AddLinkForm() | 80 add_form = AddLinkForm() |
85 | 81 |
86 return render_to_response('weblinks/add_link.html', { | 82 return render_to_response('weblinks/add_link.html', { |
87 'search_form': SearchForm(), | |
88 'add_form': add_form, | 83 'add_form': add_form, |
89 }, | 84 }, |
90 context_instance = RequestContext(request)) | 85 context_instance = RequestContext(request)) |
91 | 86 |
92 ####################################################################### | 87 ####################################################################### |
93 | 88 |
94 @login_required | 89 @login_required |
95 def add_thanks(request): | 90 def add_thanks(request): |
96 return render_to_response('weblinks/add_link.html', { | 91 return render_to_response('weblinks/add_link.html', { |
97 'search_form': SearchForm(), | |
98 }, | 92 }, |
99 context_instance = RequestContext(request)) | 93 context_instance = RequestContext(request)) |
100 | 94 |
101 ####################################################################### | 95 ####################################################################### |
102 | 96 |
129 | 123 |
130 return render_to_response('weblinks/view_links.html', { | 124 return render_to_response('weblinks/view_links.html', { |
131 's' : sort, | 125 's' : sort, |
132 'category' : cat, | 126 'category' : cat, |
133 'page' : the_page, | 127 'page' : the_page, |
134 'search_form': SearchForm(), | |
135 }, | 128 }, |
136 context_instance = RequestContext(request)) | 129 context_instance = RequestContext(request)) |
137 | 130 |
138 ####################################################################### | 131 ####################################################################### |
139 | 132 |
171 """) | 164 """) |
172 return HttpResponseRedirect(reverse('weblinks.views.report_thanks', args = (link_id, ))) | 165 return HttpResponseRedirect(reverse('weblinks.views.report_thanks', args = (link_id, ))) |
173 | 166 |
174 return render_to_response('weblinks/report_link.html', { | 167 return render_to_response('weblinks/report_link.html', { |
175 'link': link, | 168 'link': link, |
176 'search_form': SearchForm(), | |
177 'report_thanks': False, | 169 'report_thanks': False, |
178 }, | 170 }, |
179 context_instance = RequestContext(request)) | 171 context_instance = RequestContext(request)) |
180 | 172 |
181 | 173 |
184 @login_required | 176 @login_required |
185 def report_thanks(request, link_id): | 177 def report_thanks(request, link_id): |
186 link = get_object_or_404(Link, pk = link_id) | 178 link = get_object_or_404(Link, pk = link_id) |
187 return render_to_response('weblinks/report_link.html', { | 179 return render_to_response('weblinks/report_link.html', { |
188 'link': link, | 180 'link': link, |
189 'search_form': SearchForm(), | |
190 'report_thanks': True, | 181 'report_thanks': True, |
191 }, | 182 }, |
192 context_instance = RequestContext(request)) | 183 context_instance = RequestContext(request)) |
193 | 184 |
194 ####################################################################### | 185 ####################################################################### |
219 raise Http404 | 210 raise Http404 |
220 | 211 |
221 return render_to_response('weblinks/search_results.html', { | 212 return render_to_response('weblinks/search_results.html', { |
222 'query': query_text, | 213 'query': query_text, |
223 'page': the_page, | 214 'page': the_page, |
224 'search_form': SearchForm(), | |
225 }, | 215 }, |
226 context_instance = RequestContext(request)) | 216 context_instance = RequestContext(request)) |
227 | 217 |
228 ####################################################################### | 218 ####################################################################### |
229 | 219 |
230 def link_detail(request, id): | 220 def link_detail(request, id): |
231 link = get_object_or_404(Link, pk=id) | 221 link = get_object_or_404(Link, pk=id) |
232 return render_to_response('weblinks/link_detail.html', { | 222 return render_to_response('weblinks/link_detail.html', { |
233 'link': link, | 223 'link': link, |
234 'search_form': SearchForm(), | |
235 }, | 224 }, |
236 context_instance = RequestContext(request)) | 225 context_instance = RequestContext(request)) |