Mercurial > public > sg101
comparison news/views.py @ 1140:97f92a589de7
Work in progress converting news to V3 design.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Mon, 31 Oct 2016 20:39:21 -0500 |
parents | e932f2ecd4a7 |
children |
comparison
equal
deleted
inserted
replaced
1139:bb82177cc236 | 1140:97f92a589de7 |
---|---|
55 attach_extra_attrs(the_page.object_list) | 55 attach_extra_attrs(the_page.object_list) |
56 | 56 |
57 return render(request, 'news/index.html', { | 57 return render(request, 'news/index.html', { |
58 'title': 'Main Index', | 58 'title': 'Main Index', |
59 'page': the_page, | 59 'page': the_page, |
60 'section': 'main', | |
61 'V3_DESIGN': True, | |
60 }) | 62 }) |
61 | 63 |
62 ####################################################################### | 64 ####################################################################### |
63 | 65 |
64 def archive_index(request): | 66 def archive_index(request): |
65 dates = Story.objects.dates('date_submitted', 'month', order='DESC') | 67 dates = Story.objects.dates('date_submitted', 'month', order='DESC') |
66 return render(request, 'news/archive_index.html', { | 68 return render(request, 'news/archive_index.html', { |
67 'title': 'News Archive', | 69 'title': 'News Archive', |
68 'dates': dates, | 70 'dates': dates, |
71 'section': 'archives', | |
72 'V3_DESIGN': True, | |
69 }) | 73 }) |
70 | 74 |
71 ####################################################################### | 75 ####################################################################### |
72 | 76 |
73 def archive(request, year, month): | 77 def archive(request, year, month): |
86 month_name = datetime.date(int(year), int(month), 1).strftime('%B') | 90 month_name = datetime.date(int(year), int(month), 1).strftime('%B') |
87 | 91 |
88 return render(request, 'news/index.html', { | 92 return render(request, 'news/index.html', { |
89 'title': 'Archive for %s, %s' % (month_name, year), | 93 'title': 'Archive for %s, %s' % (month_name, year), |
90 'page': the_page, | 94 'page': the_page, |
95 'section': 'archives', | |
96 'V3_DESIGN': True, | |
91 }) | 97 }) |
92 | 98 |
93 ####################################################################### | 99 ####################################################################### |
94 | 100 |
95 def category_index(request): | 101 def category_index(request): |
98 for cat in categories: | 104 for cat in categories: |
99 cat_list.append((cat, cat.story_set.defer('tags')[:10])) | 105 cat_list.append((cat, cat.story_set.defer('tags')[:10])) |
100 | 106 |
101 return render(request, 'news/category_index.html', { | 107 return render(request, 'news/category_index.html', { |
102 'cat_list': cat_list, | 108 'cat_list': cat_list, |
109 'section': 'categories', | |
110 'V3_DESIGN': True, | |
103 }) | 111 }) |
104 | 112 |
105 ####################################################################### | 113 ####################################################################### |
106 | 114 |
107 def category(request, slug): | 115 def category(request, slug): |
118 attach_extra_attrs(the_page.object_list) | 126 attach_extra_attrs(the_page.object_list) |
119 | 127 |
120 return render(request, 'news/index.html', { | 128 return render(request, 'news/index.html', { |
121 'title': 'Category: ' + category.title, | 129 'title': 'Category: ' + category.title, |
122 'page': the_page, | 130 'page': the_page, |
131 'section': 'categories', | |
132 'V3_DESIGN': True, | |
123 }) | 133 }) |
124 | 134 |
125 ####################################################################### | 135 ####################################################################### |
126 | 136 |
127 def story(request, story_id): | 137 def story(request, story_id): |
128 story = get_object_or_404(Story.objects.select_related( | 138 story = get_object_or_404(Story.objects.select_related( |
129 'submitter', 'category', 'forums_topic'), pk=story_id) | 139 'submitter', 'category', 'forums_topic'), pk=story_id) |
130 return render(request, 'news/story.html', { | 140 return render(request, 'news/story.html', { |
131 'story': story, | 141 'story': story, |
142 'V3_DESIGN': True, | |
132 }) | 143 }) |
133 | 144 |
134 ####################################################################### | 145 ####################################################################### |
135 | 146 |
136 @login_required | 147 @login_required |
143 else: | 154 else: |
144 add_form = AddNewsForm() | 155 add_form = AddNewsForm() |
145 | 156 |
146 return render(request, 'news/submit_news.html', { | 157 return render(request, 'news/submit_news.html', { |
147 'add_form': add_form, | 158 'add_form': add_form, |
159 'section': 'submit', | |
160 'V3_DESIGN': True, | |
148 }) | 161 }) |
149 | 162 |
150 ####################################################################### | 163 ####################################################################### |
151 | 164 |
152 @login_required | 165 @login_required |
153 def submit_thanks(request): | 166 def submit_thanks(request): |
154 return render(request, 'news/submit_news.html') | 167 return render(request, 'news/submit_news.html', { |
168 'V3_DESIGN': True, | |
169 }) | |
155 | 170 |
156 ####################################################################### | 171 ####################################################################### |
157 | 172 |
158 def tags(request): | 173 def tags(request): |
159 tags = Tag.objects.cloud_for_model(Story) | 174 tags = Tag.objects.cloud_for_model(Story) |
160 return render(request, 'news/tag_index.html', { | 175 return render(request, 'news/tag_index.html', { |
161 'tags': tags, | 176 'tags': tags, |
177 'section': 'tags', | |
178 'V3_DESIGN': True, | |
162 }) | 179 }) |
163 | 180 |
164 ####################################################################### | 181 ####################################################################### |
165 | 182 |
166 def tag(request, tag_name): | 183 def tag(request, tag_name): |
178 attach_extra_attrs(the_page.object_list) | 195 attach_extra_attrs(the_page.object_list) |
179 | 196 |
180 return render(request, 'news/index.html', { | 197 return render(request, 'news/index.html', { |
181 'title': 'Stories with tag: "%s"' % tag_name, | 198 'title': 'Stories with tag: "%s"' % tag_name, |
182 'page': the_page, | 199 'page': the_page, |
200 'V3_DESIGN': True, | |
183 }) | 201 }) |
184 | 202 |
185 ####################################################################### | 203 ####################################################################### |
186 | 204 |
187 @login_required | 205 @login_required |
206 'story_link': story.get_absolute_url(), | 224 'story_link': story.get_absolute_url(), |
207 }) | 225 }) |
208 | 226 |
209 subject = 'Interesting Story at ' + site.name | 227 subject = 'Interesting Story at ' + site.name |
210 send_mail(subject, msg, from_email, [to_email], reply_to=request.user.email) | 228 send_mail(subject, msg, from_email, [to_email], reply_to=request.user.email) |
211 return HttpResponseRedirect(reverse('news.views.email_thanks')) | 229 return HttpResponseRedirect(reverse('news.views.email_thanks', |
230 args=[story_id])) | |
212 else: | 231 else: |
213 send_form = SendStoryForm() | 232 send_form = SendStoryForm() |
214 | 233 |
215 return render(request, 'news/send_story.html', { | 234 return render(request, 'news/send_story.html', { |
216 'send_form': send_form, | 235 'send_form': send_form, |
217 'story': story, | 236 'story': story, |
218 }) | 237 'V3_DESIGN': True, |
219 | 238 }) |
220 ####################################################################### | 239 |
221 | 240 ####################################################################### |
222 @login_required | 241 |
223 def email_thanks(request): | 242 @login_required |
224 return render(request, 'news/send_story.html') | 243 def email_thanks(request, story_id): |
244 story = get_object_or_404(Story, pk=story_id) | |
245 return render(request, 'news/send_story.html', { | |
246 'story': story, | |
247 'V3_DESIGN': True, | |
248 }) |