##// END OF EJS Templates
Views refactoring
neko259 -
r900:ec6d73a4 default
parent child Browse files
Show More
@@ -1,5 +1,3 b''
1 import string
2
3 1 from django.db import transaction
4 2 from django.shortcuts import render, redirect
5 3
@@ -12,6 +10,7 b' from boards.views.banned import BannedVi'
12 10 from boards.views.base import BaseBoardView, CONTEXT_FORM
13 11 from boards.views.posting_mixin import PostMixin
14 12
13
15 14 FORM_TAGS = 'tags'
16 15 FORM_TEXT = 'text'
17 16 FORM_TITLE = 'title'
@@ -127,7 +126,9 b' class AllThreadsView(PostMixin, BaseBoar'
127 126
128 127 post = Post.objects.create_post(title=title, text=text, image=image,
129 128 ip=ip, tags=tags)
130 # FIXME
129
130 # This is required to update the threads to which posts we have replied
131 # when creating this one
131 132 post.send_to_websocket(request)
132 133
133 134 if html_response:
@@ -14,8 +14,12 b" CONTEXT_FORM = 'form'"
14 14 class BaseBoardView(View):
15 15
16 16 def get_context_data(self, **kwargs):
17 """
18 This method is deprecated. You need to use dicts instead of context
19 instances in all places it is used now.
20 """
21
17 22 request = kwargs['request']
18 # context = self._default_context(request)
19 23 context = RequestContext(request)
20 24
21 25 return context
@@ -1,3 +1,4 b''
1 PARAM_NEXT = 'next'
1 2 PARAMETER_METHOD = 'method'
2 3
3 4 from django.shortcuts import redirect
@@ -13,8 +14,8 b' class RedirectNextMixin:'
13 14 current view has finished its work.
14 15 """
15 16
16 if 'next' in request.GET:
17 next_page = request.GET['next']
17 if PARAM_NEXT in request.GET:
18 next_page = request.GET[PARAM_NEXT]
18 19 return HttpResponseRedirect(next_page)
19 20 else:
20 21 return redirect('index')
@@ -5,6 +5,8 b' from boards.abstracts.settingsmanager im'
5 5 from boards.views.base import BaseBoardView, CONTEXT_FORM
6 6 from boards.forms import SettingsForm, PlainErrorList
7 7
8 FORM_THEME = 'theme'
9
8 10 CONTEXT_HIDDEN_TAGS = 'hidden_tags'
9 11
10 12
@@ -16,7 +18,7 b' class SettingsView(BaseBoardView):'
16 18
17 19 selected_theme = settings_manager.get_theme()
18 20
19 form = SettingsForm(initial={'theme': selected_theme},
21 form = SettingsForm(initial={FORM_THEME: selected_theme},
20 22 error_class=PlainErrorList)
21 23
22 24 context[CONTEXT_FORM] = form
@@ -32,7 +34,7 b' class SettingsView(BaseBoardView):'
32 34 form = SettingsForm(request.POST, error_class=PlainErrorList)
33 35
34 36 if form.is_valid():
35 selected_theme = form.cleaned_data['theme']
37 selected_theme = form.cleaned_data[FORM_THEME]
36 38
37 39 settings_manager.set_theme(selected_theme)
38 40
@@ -6,6 +6,9 b' from boards.views.all_threads import All'
6 6 from boards.views.mixins import DispatcherMixin, RedirectNextMixin
7 7 from boards.forms import ThreadForm, PlainErrorList
8 8
9 PARAM_HIDDEN_TAGS = 'hidden_tags'
10 PARAM_FAV_TAGS = 'fav_tags'
11 PARAM_TAG = 'tag'
9 12
10 13 __author__ = 'neko259'
11 14
@@ -25,10 +28,10 b' class TagView(AllThreadsView, Dispatcher'
25 28 settings_manager = get_settings_manager(kwargs['request'])
26 29
27 30 tag = get_object_or_404(Tag, name=self.tag_name)
28 context['tag'] = tag
31 context[PARAM_TAG] = tag
29 32
30 context['fav_tags'] = settings_manager.get_fav_tags()
31 context['hidden_tags'] = settings_manager.get_hidden_tags()
33 context[PARAM_FAV_TAGS] = settings_manager.get_fav_tags()
34 context[PARAM_HIDDEN_TAGS] = settings_manager.get_hidden_tags()
32 35
33 36 return context
34 37
@@ -118,13 +118,6 b' class ThreadView(BaseBoardView, PostMixi'
118 118 """Add a new post (in thread or as a reply)."""
119 119
120 120 ip = utils.get_client_ip(request)
121 is_banned = Ban.objects.filter(ip=ip).exists()
122
123 if is_banned:
124 if html_response:
125 return redirect(BannedView().as_view())
126 else:
127 return None
128 121
129 122 data = form.cleaned_data
130 123
General Comments 0
You need to be logged in to leave comments. Login now