##// END OF EJS Templates
Redirect after sending POST to the tag page
neko259 -
r1095:e052559b default
parent child Browse files
Show More
@@ -1,107 +1,107 b''
1 from django.shortcuts import get_object_or_404
1 from django.shortcuts import get_object_or_404, redirect
2 2
3 3 from boards.abstracts.settingsmanager import get_settings_manager, \
4 4 SETTING_FAVORITE_TAGS, SETTING_HIDDEN_TAGS
5 5 from boards.models import Tag
6 6 from boards.views.all_threads import AllThreadsView, DEFAULT_PAGE
7 7 from boards.views.mixins import DispatcherMixin
8 8 from boards.forms import ThreadForm, PlainErrorList
9 9
10 10 PARAM_HIDDEN_TAGS = 'hidden_tags'
11 11 PARAM_TAG = 'tag'
12 12 PARAM_IS_FAVORITE = 'is_favorite'
13 13 PARAM_IS_HIDDEN = 'is_hidden'
14 14
15 15 __author__ = 'neko259'
16 16
17 17
18 18 class TagView(AllThreadsView, DispatcherMixin):
19 19
20 20 tag_name = None
21 21
22 22 def get_threads(self):
23 23 tag = get_object_or_404(Tag, name=self.tag_name)
24 24
25 25 hidden_tags = self.settings_manager.get_hidden_tags()
26 26
27 27 try:
28 28 hidden_tags.remove(tag)
29 29 except ValueError:
30 30 pass
31 31
32 32 return tag.get_threads().exclude(
33 33 tags__in=hidden_tags)
34 34
35 35 def get_context_data(self, **kwargs):
36 36 params = super(TagView, self).get_context_data(**kwargs)
37 37
38 38 settings_manager = get_settings_manager(kwargs['request'])
39 39
40 40 tag = get_object_or_404(Tag, name=self.tag_name)
41 41 params[PARAM_TAG] = tag
42 42
43 43 fav_tag_names = settings_manager.get_setting(SETTING_FAVORITE_TAGS)
44 44 hidden_tag_names = settings_manager.get_setting(SETTING_HIDDEN_TAGS)
45 45
46 46 params[PARAM_IS_FAVORITE] = fav_tag_names is not None and tag.name in fav_tag_names
47 47 params[PARAM_IS_HIDDEN] = hidden_tag_names is not None and tag.name in hidden_tag_names
48 48
49 49 return params
50 50
51 51 def get(self, request, tag_name, page=DEFAULT_PAGE, form=None):
52 52 self.tag_name = tag_name
53 53
54 54 return super(TagView, self).get(request, page, form)
55 55
56 56
57 57 def post(self, request, tag_name, page=DEFAULT_PAGE):
58 58 self.tag_name = tag_name
59 59
60 60 if 'method' in request.POST:
61 61 self.dispatch_method(request)
62 62 form = None
63 63 else:
64 64 form = ThreadForm(request.POST, request.FILES,
65 65 error_class=PlainErrorList)
66 66 form.session = request.session
67 67
68 68 if form.is_valid():
69 69 return self.create_thread(request, form)
70 70 if form.need_to_ban:
71 71 # Ban user because he is suspected to be a bot
72 72 self._ban_current_user(request)
73 73
74 return self.get(request, tag_name, page, form)
74 return redirect('tag', tag_name)
75 75
76 76 def subscribe(self, request):
77 77 tag = get_object_or_404(Tag, name=self.tag_name)
78 78
79 79 settings_manager = get_settings_manager(request)
80 80 settings_manager.add_fav_tag(tag)
81 81
82 82 def unsubscribe(self, request):
83 83 tag = get_object_or_404(Tag, name=self.tag_name)
84 84
85 85 settings_manager = get_settings_manager(request)
86 86 settings_manager.del_fav_tag(tag)
87 87
88 88 def hide(self, request):
89 89 """
90 90 Adds tag to user's hidden tags. Threads with this tag will not be
91 91 shown.
92 92 """
93 93
94 94 tag = get_object_or_404(Tag, name=self.tag_name)
95 95
96 96 settings_manager = get_settings_manager(request)
97 97 settings_manager.add_hidden_tag(tag)
98 98
99 99 def unhide(self, request):
100 100 """
101 101 Removed tag from user's hidden tags.
102 102 """
103 103
104 104 tag = get_object_or_404(Tag, name=self.tag_name)
105 105
106 106 settings_manager = get_settings_manager(request)
107 107 settings_manager.del_hidden_tag(tag)
General Comments 0
You need to be logged in to leave comments. Login now