Show More
@@ -14,7 +14,7 b' import neboard' | |||||
14 |
|
14 | |||
15 |
|
15 | |||
16 | def index(request, page=0): |
|
16 | def index(request, page=0): | |
17 |
context = |
|
17 | context = _init_default_context(request) | |
18 |
|
18 | |||
19 | if utils.need_include_captcha(request): |
|
19 | if utils.need_include_captcha(request): | |
20 | threadFormClass = ThreadCaptchaForm |
|
20 | threadFormClass = ThreadCaptchaForm | |
@@ -34,11 +34,8 b' def index(request, page=0):' | |||||
34 |
|
34 | |||
35 | threads = Post.objects.get_threads(page=int(page)) |
|
35 | threads = Post.objects.get_threads(page=int(page)) | |
36 |
|
36 | |||
37 | # TODO Get rid of the duplicate code in index and tag views |
|
|||
38 | context['threads'] = None if len(threads) == 0 else threads |
|
37 | context['threads'] = None if len(threads) == 0 else threads | |
39 | context['form'] = form |
|
38 | context['form'] = form | |
40 | context['tags'] = Tag.objects.get_popular_tags() |
|
|||
41 | context['theme'] = _get_theme(request) |
|
|||
42 | context['pages'] = range(Post.objects.get_thread_page_count()) |
|
39 | context['pages'] = range(Post.objects.get_thread_page_count()) | |
43 |
|
40 | |||
44 | return render(request, 'boards/posting_general.html', |
|
41 | return render(request, 'boards/posting_general.html', | |
@@ -106,11 +103,9 b' def tag(request, tag_name, page=0):' | |||||
106 | form = forms.ThreadForm(initial={'tags': tag_name}, |
|
103 | form = forms.ThreadForm(initial={'tags': tag_name}, | |
107 | error_class=PlainErrorList) |
|
104 | error_class=PlainErrorList) | |
108 |
|
105 | |||
109 |
context = |
|
106 | context = _init_default_context(request) | |
110 | context['threads'] = None if len(threads) == 0 else threads |
|
107 | context['threads'] = None if len(threads) == 0 else threads | |
111 | context['tag'] = tag_name |
|
108 | context['tag'] = tag_name | |
112 | context['tags'] = Tag.objects.get_popular_tags() |
|
|||
113 | context['theme'] = _get_theme(request) |
|
|||
114 | context['pages'] = range(Post.objects.get_thread_page_count(tag=tag)) |
|
109 | context['pages'] = range(Post.objects.get_thread_page_count(tag=tag)) | |
115 |
|
110 | |||
116 | context['form'] = form |
|
111 | context['form'] = form | |
@@ -139,12 +134,10 b' def thread(request, post_id):' | |||||
139 |
|
134 | |||
140 | posts = Post.objects.get_thread(post_id) |
|
135 | posts = Post.objects.get_thread(post_id) | |
141 |
|
136 | |||
142 |
context = |
|
137 | context = _init_default_context(request) | |
143 |
|
138 | |||
144 | context['posts'] = posts |
|
139 | context['posts'] = posts | |
145 | context['form'] = form |
|
140 | context['form'] = form | |
146 | context['tags'] = Tag.objects.get_popular_tags() |
|
|||
147 | context['theme'] = _get_theme(request) |
|
|||
148 |
|
141 | |||
149 | return render(request, 'boards/thread.html', context) |
|
142 | return render(request, 'boards/thread.html', context) | |
150 |
|
143 | |||
@@ -178,6 +171,8 b' def logout(request):' | |||||
178 |
|
171 | |||
179 |
|
172 | |||
180 | def settings(request): |
|
173 | def settings(request): | |
|
174 | """User's settings""" | |||
|
175 | ||||
181 | context = RequestContext(request) |
|
176 | context = RequestContext(request) | |
182 |
|
177 | |||
183 | if request.method == 'POST': |
|
178 | if request.method == 'POST': | |
@@ -198,15 +193,17 b' def settings(request):' | |||||
198 |
|
193 | |||
199 |
|
194 | |||
200 | def all_tags(request): |
|
195 | def all_tags(request): | |
201 | context = RequestContext(request) |
|
196 | """All tags list""" | |
202 | context['tags'] = Tag.objects.get_popular_tags() |
|
197 | ||
203 |
context |
|
198 | context = _init_default_context(request) | |
204 | context['all_tags'] = Tag.objects.get_not_empty_tags() |
|
199 | context['all_tags'] = Tag.objects.get_not_empty_tags() | |
205 |
|
200 | |||
206 | return render(request, 'boards/tags.html', context) |
|
201 | return render(request, 'boards/tags.html', context) | |
207 |
|
202 | |||
208 |
|
203 | |||
209 | def jump_to_post(request, post_id): |
|
204 | def jump_to_post(request, post_id): | |
|
205 | """Determine thread in which the requested post is and open it's page""" | |||
|
206 | ||||
210 | post = get_object_or_404(Post, id=post_id) |
|
207 | post = get_object_or_404(Post, id=post_id) | |
211 |
|
208 | |||
212 | if boards.models.NO_PARENT == post.parent: |
|
209 | if boards.models.NO_PARENT == post.parent: | |
@@ -218,6 +215,8 b' def jump_to_post(request, post_id):' | |||||
218 |
|
215 | |||
219 |
|
216 | |||
220 | def _get_theme(request): |
|
217 | def _get_theme(request): | |
|
218 | """Get user's CSS theme""" | |||
|
219 | ||||
221 | return request.session.get('theme', neboard.settings.DEFAULT_THEME) |
|
220 | return request.session.get('theme', neboard.settings.DEFAULT_THEME) | |
222 |
|
221 | |||
223 |
|
222 | |||
@@ -228,3 +227,13 b' def _get_client_ip(request):' | |||||
228 | else: |
|
227 | else: | |
229 | ip = request.META.get('REMOTE_ADDR') |
|
228 | ip = request.META.get('REMOTE_ADDR') | |
230 | return ip |
|
229 | return ip | |
|
230 | ||||
|
231 | ||||
|
232 | def _init_default_context(request): | |||
|
233 | """Create context with default values that are used in most views""" | |||
|
234 | ||||
|
235 | context = RequestContext(request) | |||
|
236 | context['tags'] = Tag.objects.get_popular_tags() | |||
|
237 | context['theme'] = _get_theme(request) | |||
|
238 | ||||
|
239 | return context |
General Comments 0
You need to be logged in to leave comments.
Login now