##// END OF EJS Templates
Made "subscribe" and "hide" in tags as buttons with forms.
neko259 -
r1037:9a07761c default
parent child Browse files
Show More
@@ -1,81 +1,91 b''
1 .ui-button {
1 .ui-button {
2 display: none;
2 display: none;
3 }
3 }
4
4
5 .ui-dialog-content {
5 .ui-dialog-content {
6 padding: 0;
6 padding: 0;
7 min-height: 0;
7 min-height: 0;
8 }
8 }
9
9
10 .mark_btn {
10 .mark_btn {
11 cursor: pointer;
11 cursor: pointer;
12 }
12 }
13
13
14 .img-full {
14 .img-full {
15 position: fixed;
15 position: fixed;
16 background-color: #CCC;
16 background-color: #CCC;
17 border: 1px solid #000;
17 border: 1px solid #000;
18 cursor: pointer;
18 cursor: pointer;
19 }
19 }
20
20
21 .strikethrough {
21 .strikethrough {
22 text-decoration: line-through;
22 text-decoration: line-through;
23 }
23 }
24
24
25 .post_preview {
25 .post_preview {
26 z-index: 300;
26 z-index: 300;
27 position:absolute;
27 position:absolute;
28 }
28 }
29
29
30 .gallery_image {
30 .gallery_image {
31 display: inline-block;
31 display: inline-block;
32 }
32 }
33
33
34 @media print {
34 @media print {
35 .post-form-w {
35 .post-form-w {
36 display: none;
36 display: none;
37 }
37 }
38 }
38 }
39
39
40 input[name="image"] {
40 input[name="image"] {
41 display: block;
41 display: block;
42 width: 100px;
42 width: 100px;
43 height: 100px;
43 height: 100px;
44 cursor: pointer;
44 cursor: pointer;
45 position: absolute;
45 position: absolute;
46 opacity: 0;
46 opacity: 0;
47 z-index: 1;
47 z-index: 1;
48 }
48 }
49
49
50 .file_wrap {
50 .file_wrap {
51 width: 100px;
51 width: 100px;
52 height: 100px;
52 height: 100px;
53 border: solid 1px white;
53 border: solid 1px white;
54 display: inline-block;
54 display: inline-block;
55 }
55 }
56
56
57 form > .file_wrap {
57 form > .file_wrap {
58 float: left;
58 float: left;
59 }
59 }
60
60
61 .file-thumb {
61 .file-thumb {
62 width: 100px;
62 width: 100px;
63 height: 100px;
63 height: 100px;
64 background-size: cover;
64 background-size: cover;
65 background-position: center;
65 background-position: center;
66 }
66 }
67
67
68 .compact-form-text {
68 .compact-form-text {
69 margin-left:110px;
69 margin-left:110px;
70 }
70 }
71
71
72 textarea, input {
72 textarea, input {
73 -moz-box-sizing: border-box;
73 -moz-box-sizing: border-box;
74 -webkit-box-sizing: border-box;
74 -webkit-box-sizing: border-box;
75 box-sizing: border-box;
75 box-sizing: border-box;
76 }
76 }
77
77
78 .compact-form-text > textarea {
78 .compact-form-text > textarea {
79 height: 100px;
79 height: 100px;
80 width: 100%;
80 width: 100%;
81 }
81 }
82
83 .post-button-form {
84 display: inline;
85 }
86
87 .post-button-form > input[type="submit"] {
88 border: none;
89 margin: 0;
90 padding: 0;
91 }
@@ -1,99 +1,116 b''
1 /*
1 /*
2 @licstart The following is the entire license notice for the
2 @licstart The following is the entire license notice for the
3 JavaScript code in this page.
3 JavaScript code in this page.
4
4
5
5
6 Copyright (C) 2013 neko259
6 Copyright (C) 2013 neko259
7
7
8 The JavaScript code in this page is free software: you can
8 The JavaScript code in this page is free software: you can
9 redistribute it and/or modify it under the terms of the GNU
9 redistribute it and/or modify it under the terms of the GNU
10 General Public License (GNU GPL) as published by the Free Software
10 General Public License (GNU GPL) as published by the Free Software
11 Foundation, either version 3 of the License, or (at your option)
11 Foundation, either version 3 of the License, or (at your option)
12 any later version. The code is distributed WITHOUT ANY WARRANTY;
12 any later version. The code is distributed WITHOUT ANY WARRANTY;
13 without even the implied warranty of MERCHANTABILITY or FITNESS
13 without even the implied warranty of MERCHANTABILITY or FITNESS
14 FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
14 FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
15
15
16 As additional permission under GNU GPL version 3 section 7, you
16 As additional permission under GNU GPL version 3 section 7, you
17 may distribute non-source (e.g., minimized or compacted) forms of
17 may distribute non-source (e.g., minimized or compacted) forms of
18 that code without the copy of the GNU GPL normally required by
18 that code without the copy of the GNU GPL normally required by
19 section 4, provided you include this license notice and a URL
19 section 4, provided you include this license notice and a URL
20 through which recipients can access the Corresponding Source.
20 through which recipients can access the Corresponding Source.
21
21
22 @licend The above is the entire license notice
22 @licend The above is the entire license notice
23 for the JavaScript code in this page.
23 for the JavaScript code in this page.
24 */
24 */
25
25
26 if (window.Intl) {
26 if (window.Intl) {
27 var LOCALE = window.navigator.language;
27 var LOCALE = window.navigator.language;
28 var FORMATTER = new Intl.DateTimeFormat(
28 var FORMATTER = new Intl.DateTimeFormat(
29 LOCALE,
29 LOCALE,
30 {
30 {
31 weekday: 'short', year: 'numeric', month: 'short', day: 'numeric',
31 weekday: 'short', year: 'numeric', month: 'short', day: 'numeric',
32 hour: 'numeric', minute: '2-digit', second: '2-digit'
32 hour: 'numeric', minute: '2-digit', second: '2-digit'
33 }
33 }
34 );
34 );
35 }
35 }
36
36
37 /**
37 /**
38 * An email is a hidden file to prevent spam bots from posting. It has to be
38 * An email is a hidden file to prevent spam bots from posting. It has to be
39 * hidden.
39 * hidden.
40 */
40 */
41 function hideEmailFromForm() {
41 function hideEmailFromForm() {
42 $('.form-email').parent().parent().hide();
42 $('.form-email').parent().parent().hide();
43 }
43 }
44
44
45 /**
45 /**
46 * Highlight code blocks with code highlighter
46 * Highlight code blocks with code highlighter
47 */
47 */
48 function highlightCode(node) {
48 function highlightCode(node) {
49 node.find('pre code').each(function(i, e) {
49 node.find('pre code').each(function(i, e) {
50 hljs.highlightBlock(e);
50 hljs.highlightBlock(e);
51 });
51 });
52 }
52 }
53
53
54 /**
54 /**
55 * Translate timestamps to local ones for all <time> tags inside node.
55 * Translate timestamps to local ones for all <time> tags inside node.
56 */
56 */
57 function translate_time(node) {
57 function translate_time(node) {
58 if (window.Intl === null) {
58 if (window.Intl === null) {
59 return;
59 return;
60 }
60 }
61
61
62 var elements;
62 var elements;
63
63
64 if (node === null) {
64 if (node === null) {
65 elements = $('time');
65 elements = $('time');
66 } else {
66 } else {
67 elements = node.find('time');
67 elements = node.find('time');
68 }
68 }
69
69
70 if (!elements.length) {
70 if (!elements.length) {
71 return;
71 return;
72 }
72 }
73
73
74 elements.each(function() {
74 elements.each(function() {
75 var element = $(this);
75 var element = $(this);
76 var dateAttr = element.attr('datetime');
76 var dateAttr = element.attr('datetime');
77 if (dateAttr) {
77 if (dateAttr) {
78 var date = new Date(dateAttr);
78 var date = new Date(dateAttr);
79 element.text(FORMATTER.format(date));
79 element.text(FORMATTER.format(date));
80 }
80 }
81 });
81 });
82 }
82 }
83
83
84 /**
85 * We use buttons viewed as a form with link and hidden inputs to ensure
86 * the search crawlers don't index or click them.
87 *
88 * But we need to submit the form by clicking the links. That's why these
89 * handlers are here.
90 */
91 function addPostButtonActions() {
92 $('.post-button-form > a').each(function() {
93 $(this).click(function() {
94 $(this).parent().submit();
95 });
96 });
97 }
98
84 $( document ).ready(function() {
99 $( document ).ready(function() {
85 hideEmailFromForm();
100 hideEmailFromForm();
86
101
87 $("a[href='#top']").click(function() {
102 $("a[href='#top']").click(function() {
88 $("html, body").animate({ scrollTop: 0 }, "slow");
103 $("html, body").animate({ scrollTop: 0 }, "slow");
89 return false;
104 return false;
90 });
105 });
91
106
92 addImgPreview();
107 addImgPreview();
93
108
94 addRefLinkPreview();
109 addRefLinkPreview();
95
110
96 highlightCode($(document));
111 highlightCode($(document));
97
112
98 translate_time(null);
113 translate_time(null);
114
115 addPostButtonActions();
99 });
116 });
@@ -1,190 +1,193 b''
1 {% extends "boards/base.html" %}
1 {% extends "boards/base.html" %}
2
2
3 {% load i18n %}
3 {% load i18n %}
4 {% load cache %}
4 {% load cache %}
5 {% load board %}
5 {% load board %}
6 {% load static %}
6 {% load static %}
7
7
8 {% block head %}
8 {% block head %}
9 {% if tag %}
9 {% if tag %}
10 <title>{{ tag.name }} - {{ site_name }}</title>
10 <title>{{ tag.name }} - {{ site_name }}</title>
11 {% else %}
11 {% else %}
12 <title>{{ site_name }}</title>
12 <title>{{ site_name }}</title>
13 {% endif %}
13 {% endif %}
14
14
15 {% if current_page.has_previous %}
15 {% if current_page.has_previous %}
16 <link rel="prev" href="
16 <link rel="prev" href="
17 {% if tag %}
17 {% if tag %}
18 {% url "tag" tag_name=tag.name page=current_page.previous_page_number %}
18 {% url "tag" tag_name=tag.name page=current_page.previous_page_number %}
19 {% else %}
19 {% else %}
20 {% url "index" page=current_page.previous_page_number %}
20 {% url "index" page=current_page.previous_page_number %}
21 {% endif %}
21 {% endif %}
22 " />
22 " />
23 {% endif %}
23 {% endif %}
24 {% if current_page.has_next %}
24 {% if current_page.has_next %}
25 <link rel="next" href="
25 <link rel="next" href="
26 {% if tag %}
26 {% if tag %}
27 {% url "tag" tag_name=tag.name page=current_page.next_page_number %}
27 {% url "tag" tag_name=tag.name page=current_page.next_page_number %}
28 {% else %}
28 {% else %}
29 {% url "index" page=current_page.next_page_number %}
29 {% url "index" page=current_page.next_page_number %}
30 {% endif %}
30 {% endif %}
31 " />
31 " />
32 {% endif %}
32 {% endif %}
33
33
34 {% endblock %}
34 {% endblock %}
35
35
36 {% block content %}
36 {% block content %}
37
37
38 {% get_current_language as LANGUAGE_CODE %}
38 {% get_current_language as LANGUAGE_CODE %}
39
39
40 {% if tag %}
40 {% if tag %}
41 <div class="tag_info">
41 <div class="tag_info">
42 <h2>
42 <h2>
43 {% if is_favorite %}
43 <form action="{% url 'tag' tag.name %}" method="post" class="post-button-form">
44 <a href="{% url 'tag' tag.name %}?method=unsubscribe&next={{ request.path }}"
44 <input type="hidden" name="method"
45 class="fav" rel="nofollow">β˜…</a>
45 {% if is_favorite %}
46 {% else %}
46 <input type="hidden" name="method" value="unsubscribe" />
47 <a href="{% url 'tag' tag.name %}?method=subscribe&next={{ request.path }}"
47 <a class="fav" href="#">β˜…</a>
48 class="not_fav" rel="nofollow">β˜…</a>
48 {% else %}
49 {% endif %}
49 <input type="hidden" name="method" value="subscribe" />
50 {% if is_hidden %}
50 <a class="not_fav" href="#">β˜…</a>
51 <a href="{% url 'tag' tag.name %}?method=unhide&next={{ request.path }}"
51 {% endif %}
52 title="{% trans 'Show tag' %}"
52 </form>
53 class="fav" rel="nofollow">H</a>
53 <form action="{% url 'tag' tag.name %}" method="post" class="post-button-form">
54 {% else %}
54 {% if is_hidden %}
55 <a href="{% url 'tag' tag.name %}?method=hide&next={{ request.path }}"
55 <input type="hidden" name="method" value="unhide" />
56 title="{% trans 'Hide tag' %}"
56 <a class="fav" href="#">H</a>
57 class="not_fav" rel="nofollow">H</a>
57 {% else %}
58 {% endif %}
58 <input type="hidden" name="method" value="hide" />
59 <a class="not_fav" href="#">H</a>
60 {% endif %}
61 </form>
59 {% autoescape off %}
62 {% autoescape off %}
60 {{ tag.get_view }}
63 {{ tag.get_view }}
61 {% endautoescape %}
64 {% endautoescape %}
62 {% if moderator %}
65 {% if moderator %}
63 <span class="moderator_info">[<a href="{% url 'admin:boards_tag_change' tag.id %}">{% trans 'Edit tag' %}</a>]</span>
66 <span class="moderator_info">[<a href="{% url 'admin:boards_tag_change' tag.id %}">{% trans 'Edit tag' %}</a>]</span>
64 {% endif %}
67 {% endif %}
65 </h2>
68 </h2>
66 <p>{% blocktrans with thread_count=tag.get_thread_count post_count=tag.get_post_count %}This tag has {{ thread_count }} threads and {{ post_count }} posts.{% endblocktrans %}</p>
69 <p>{% blocktrans with thread_count=tag.get_thread_count post_count=tag.get_post_count %}This tag has {{ thread_count }} threads and {{ post_count }} posts.{% endblocktrans %}</p>
67 </div>
70 </div>
68 {% endif %}
71 {% endif %}
69
72
70 {% if threads %}
73 {% if threads %}
71 {% if current_page.has_previous %}
74 {% if current_page.has_previous %}
72 <div class="page_link">
75 <div class="page_link">
73 <a href="
76 <a href="
74 {% if tag %}
77 {% if tag %}
75 {% url "tag" tag_name=tag.name page=current_page.previous_page_number %}
78 {% url "tag" tag_name=tag.name page=current_page.previous_page_number %}
76 {% else %}
79 {% else %}
77 {% url "index" page=current_page.previous_page_number %}
80 {% url "index" page=current_page.previous_page_number %}
78 {% endif %}
81 {% endif %}
79 ">{% trans "Previous page" %}</a>
82 ">{% trans "Previous page" %}</a>
80 </div>
83 </div>
81 {% endif %}
84 {% endif %}
82
85
83 {% for thread in threads %}
86 {% for thread in threads %}
84 {% cache 600 thread_short thread.id thread.last_edit_time moderator LANGUAGE_CODE %}
87 {% cache 600 thread_short thread.id thread.last_edit_time moderator LANGUAGE_CODE %}
85 <div class="thread">
88 <div class="thread">
86 {% post_view thread.get_opening_post moderator is_opening=True thread=thread truncated=True need_open_link=True %}
89 {% post_view thread.get_opening_post moderator is_opening=True thread=thread truncated=True need_open_link=True %}
87 {% if not thread.archived %}
90 {% if not thread.archived %}
88 {% with last_replies=thread.get_last_replies %}
91 {% with last_replies=thread.get_last_replies %}
89 {% if last_replies %}
92 {% if last_replies %}
90 {% with skipped_replies_count=thread.get_skipped_replies_count %}
93 {% with skipped_replies_count=thread.get_skipped_replies_count %}
91 {% if skipped_replies_count %}
94 {% if skipped_replies_count %}
92 <div class="skipped_replies">
95 <div class="skipped_replies">
93 <a href="{% url 'thread' thread.get_opening_post_id %}">
96 <a href="{% url 'thread' thread.get_opening_post_id %}">
94 {% blocktrans with count=skipped_replies_count %}Skipped {{ count }} replies. Open thread to see all replies.{% endblocktrans %}
97 {% blocktrans with count=skipped_replies_count %}Skipped {{ count }} replies. Open thread to see all replies.{% endblocktrans %}
95 </a>
98 </a>
96 </div>
99 </div>
97 {% endif %}
100 {% endif %}
98 {% endwith %}
101 {% endwith %}
99 <div class="last-replies">
102 <div class="last-replies">
100 {% for post in last_replies %}
103 {% for post in last_replies %}
101 {% post_view post is_opening=False moderator=moderator truncated=True %}
104 {% post_view post is_opening=False moderator=moderator truncated=True %}
102 {% endfor %}
105 {% endfor %}
103 </div>
106 </div>
104 {% endif %}
107 {% endif %}
105 {% endwith %}
108 {% endwith %}
106 {% endif %}
109 {% endif %}
107 </div>
110 </div>
108 {% endcache %}
111 {% endcache %}
109 {% endfor %}
112 {% endfor %}
110
113
111 {% if current_page.has_next %}
114 {% if current_page.has_next %}
112 <div class="page_link">
115 <div class="page_link">
113 <a href="
116 <a href="
114 {% if tag %}
117 {% if tag %}
115 {% url "tag" tag_name=tag.name page=current_page.next_page_number %}
118 {% url "tag" tag_name=tag.name page=current_page.next_page_number %}
116 {% else %}
119 {% else %}
117 {% url "index" page=current_page.next_page_number %}
120 {% url "index" page=current_page.next_page_number %}
118 {% endif %}
121 {% endif %}
119 ">{% trans "Next page" %}</a>
122 ">{% trans "Next page" %}</a>
120 </div>
123 </div>
121 {% endif %}
124 {% endif %}
122 {% else %}
125 {% else %}
123 <div class="post">
126 <div class="post">
124 {% trans 'No threads exist. Create the first one!' %}</div>
127 {% trans 'No threads exist. Create the first one!' %}</div>
125 {% endif %}
128 {% endif %}
126
129
127 <div class="post-form-w">
130 <div class="post-form-w">
128 <script src="{% static 'js/panel.js' %}"></script>
131 <script src="{% static 'js/panel.js' %}"></script>
129 <div class="post-form">
132 <div class="post-form">
130 <div class="form-title">{% trans "Create new thread" %}</div>
133 <div class="form-title">{% trans "Create new thread" %}</div>
131 <div class="swappable-form-full">
134 <div class="swappable-form-full">
132 <form enctype="multipart/form-data" method="post" id="form">{% csrf_token %}
135 <form enctype="multipart/form-data" method="post" id="form">{% csrf_token %}
133 {{ form.as_div }}
136 {{ form.as_div }}
134 <div class="form-submit">
137 <div class="form-submit">
135 <input type="submit" value="{% trans "Post" %}"/>
138 <input type="submit" value="{% trans "Post" %}"/>
136 </div>
139 </div>
137 (ctrl-enter)
140 (ctrl-enter)
138 </form>
141 </form>
139 </div>
142 </div>
140 <div>
143 <div>
141 {% trans 'Tags must be delimited by spaces. Text or image is required.' %}
144 {% trans 'Tags must be delimited by spaces. Text or image is required.' %}
142 </div>
145 </div>
143 <div><a href="{% url "staticpage" name="help" %}">
146 <div><a href="{% url "staticpage" name="help" %}">
144 {% trans 'Text syntax' %}</a></div>
147 {% trans 'Text syntax' %}</a></div>
145 </div>
148 </div>
146 </div>
149 </div>
147
150
148 <script src="{% static 'js/form.js' %}"></script>
151 <script src="{% static 'js/form.js' %}"></script>
149
152
150 {% endblock %}
153 {% endblock %}
151
154
152 {% block metapanel %}
155 {% block metapanel %}
153
156
154 <span class="metapanel">
157 <span class="metapanel">
155 <b><a href="{% url "authors" %}">{{ site_name }}</a> {{ version }}</b>
158 <b><a href="{% url "authors" %}">{{ site_name }}</a> {{ version }}</b>
156 {% trans "Pages:" %}
159 {% trans "Pages:" %}
157 <a href="
160 <a href="
158 {% if tag %}
161 {% if tag %}
159 {% url "tag" tag_name=tag.name page=paginator.page_range|first %}
162 {% url "tag" tag_name=tag.name page=paginator.page_range|first %}
160 {% else %}
163 {% else %}
161 {% url "index" page=paginator.page_range|first %}
164 {% url "index" page=paginator.page_range|first %}
162 {% endif %}
165 {% endif %}
163 ">&lt;&lt;</a>
166 ">&lt;&lt;</a>
164 [
167 [
165 {% for page in paginator.center_range %}
168 {% for page in paginator.center_range %}
166 <a
169 <a
167 {% ifequal page current_page.number %}
170 {% ifequal page current_page.number %}
168 class="current_page"
171 class="current_page"
169 {% endifequal %}
172 {% endifequal %}
170 href="
173 href="
171 {% if tag %}
174 {% if tag %}
172 {% url "tag" tag_name=tag.name page=page %}
175 {% url "tag" tag_name=tag.name page=page %}
173 {% else %}
176 {% else %}
174 {% url "index" page=page %}
177 {% url "index" page=page %}
175 {% endif %}
178 {% endif %}
176 ">{{ page }}</a>
179 ">{{ page }}</a>
177 {% if not forloop.last %},{% endif %}
180 {% if not forloop.last %},{% endif %}
178 {% endfor %}
181 {% endfor %}
179 ]
182 ]
180 <a href="
183 <a href="
181 {% if tag %}
184 {% if tag %}
182 {% url "tag" tag_name=tag.name page=paginator.page_range|last %}
185 {% url "tag" tag_name=tag.name page=paginator.page_range|last %}
183 {% else %}
186 {% else %}
184 {% url "index" page=paginator.page_range|last %}
187 {% url "index" page=paginator.page_range|last %}
185 {% endif %}
188 {% endif %}
186 ">&gt;&gt;</a>
189 ">&gt;&gt;</a>
187 [<a href="rss/">RSS</a>]
190 [<a href="rss/">RSS</a>]
188 </span>
191 </span>
189
192
190 {% endblock %}
193 {% endblock %}
@@ -1,100 +1,99 b''
1 from django.shortcuts import get_object_or_404
1 from django.shortcuts import get_object_or_404
2
2
3 from boards.abstracts.settingsmanager import get_settings_manager, \
3 from boards.abstracts.settingsmanager import get_settings_manager, \
4 SETTING_FAVORITE_TAGS, SETTING_HIDDEN_TAGS
4 SETTING_FAVORITE_TAGS, SETTING_HIDDEN_TAGS
5 from boards.models import Tag, Thread
5 from boards.models import Tag, Thread
6 from boards.views.all_threads import AllThreadsView, DEFAULT_PAGE
6 from boards.views.all_threads import AllThreadsView, DEFAULT_PAGE
7 from boards.views.mixins import DispatcherMixin, RedirectNextMixin
7 from boards.views.mixins import DispatcherMixin, RedirectNextMixin
8 from boards.forms import ThreadForm, PlainErrorList
8 from boards.forms import ThreadForm, PlainErrorList
9
9
10 PARAM_HIDDEN_TAGS = 'hidden_tags'
10 PARAM_HIDDEN_TAGS = 'hidden_tags'
11 PARAM_TAG = 'tag'
11 PARAM_TAG = 'tag'
12 PARAM_IS_FAVORITE = 'is_favorite'
12 PARAM_IS_FAVORITE = 'is_favorite'
13 PARAM_IS_HIDDEN = 'is_hidden'
13 PARAM_IS_HIDDEN = 'is_hidden'
14
14
15 __author__ = 'neko259'
15 __author__ = 'neko259'
16
16
17
17
18 class TagView(AllThreadsView, DispatcherMixin, RedirectNextMixin):
18 class TagView(AllThreadsView, DispatcherMixin, RedirectNextMixin):
19
19
20 tag_name = None
20 tag_name = None
21
21
22 def get_threads(self):
22 def get_threads(self):
23 tag = get_object_or_404(Tag, name=self.tag_name)
23 tag = get_object_or_404(Tag, name=self.tag_name)
24
24
25 return tag.get_threads()
25 return tag.get_threads()
26
26
27 def get_context_data(self, **kwargs):
27 def get_context_data(self, **kwargs):
28 params = super(TagView, self).get_context_data(**kwargs)
28 params = super(TagView, self).get_context_data(**kwargs)
29
29
30 settings_manager = get_settings_manager(kwargs['request'])
30 settings_manager = get_settings_manager(kwargs['request'])
31
31
32 tag = get_object_or_404(Tag, name=self.tag_name)
32 tag = get_object_or_404(Tag, name=self.tag_name)
33 params[PARAM_TAG] = tag
33 params[PARAM_TAG] = tag
34
34
35 fav_tag_names = settings_manager.get_setting(SETTING_FAVORITE_TAGS)
35 fav_tag_names = settings_manager.get_setting(SETTING_FAVORITE_TAGS)
36 hidden_tag_names = settings_manager.get_setting(SETTING_HIDDEN_TAGS)
36 hidden_tag_names = settings_manager.get_setting(SETTING_HIDDEN_TAGS)
37
37
38 params[PARAM_IS_FAVORITE] = fav_tag_names is not None and tag.name in fav_tag_names
38 params[PARAM_IS_FAVORITE] = fav_tag_names is not None and tag.name in fav_tag_names
39 params[PARAM_IS_HIDDEN] = hidden_tag_names is not None and tag.name in hidden_tag_names
39 params[PARAM_IS_HIDDEN] = hidden_tag_names is not None and tag.name in hidden_tag_names
40
40
41 return params
41 return params
42
42
43 def get(self, request, tag_name, page=DEFAULT_PAGE, form=None):
43 def get(self, request, tag_name, page=DEFAULT_PAGE, form=None):
44 self.tag_name = tag_name
44 self.tag_name = tag_name
45
45
46 dispatch_result = self.dispatch_method(request)
46 return super(TagView, self).get(request, page, form)
47 if dispatch_result:
47
48 return dispatch_result
49 else:
50 return super(TagView, self).get(request, page, form)
51
48
52 def post(self, request, tag_name, page=DEFAULT_PAGE):
49 def post(self, request, tag_name, page=DEFAULT_PAGE):
53 form = ThreadForm(request.POST, request.FILES,
50 self.tag_name = tag_name
54 error_class=PlainErrorList)
55 form.session = request.session
56
51
57 if form.is_valid():
52 if 'method' in request.POST:
58 return self.create_thread(request, form)
53 self.dispatch_method(request)
59 if form.need_to_ban:
54 form = None
60 # Ban user because he is suspected to be a bot
55 else:
61 self._ban_current_user(request)
56 form = ThreadForm(request.POST, request.FILES,
57 error_class=PlainErrorList)
58 form.session = request.session
59
60 if form.is_valid():
61 return self.create_thread(request, form)
62 if form.need_to_ban:
63 # Ban user because he is suspected to be a bot
64 self._ban_current_user(request)
62
65
63 return self.get(request, tag_name, page, form)
66 return self.get(request, tag_name, page, form)
64
67
65 def subscribe(self, request):
68 def subscribe(self, request):
66 tag = get_object_or_404(Tag, name=self.tag_name)
69 tag = get_object_or_404(Tag, name=self.tag_name)
67
70
68 settings_manager = get_settings_manager(request)
71 settings_manager = get_settings_manager(request)
69 settings_manager.add_fav_tag(tag)
72 settings_manager.add_fav_tag(tag)
70
73
71 return self.redirect_to_next(request)
72
73 def unsubscribe(self, request):
74 def unsubscribe(self, request):
74 tag = get_object_or_404(Tag, name=self.tag_name)
75 tag = get_object_or_404(Tag, name=self.tag_name)
75
76
76 settings_manager = get_settings_manager(request)
77 settings_manager = get_settings_manager(request)
77 settings_manager.del_fav_tag(tag)
78 settings_manager.del_fav_tag(tag)
78
79
79 return self.redirect_to_next(request)
80
81 def hide(self, request):
80 def hide(self, request):
82 """
81 """
83 Adds tag to user's hidden tags. Threads with this tag will not be
82 Adds tag to user's hidden tags. Threads with this tag will not be
84 shown.
83 shown.
85 """
84 """
86
85
87 tag = get_object_or_404(Tag, name=self.tag_name)
86 tag = get_object_or_404(Tag, name=self.tag_name)
88
87
89 settings_manager = get_settings_manager(request)
88 settings_manager = get_settings_manager(request)
90 settings_manager.add_hidden_tag(tag)
89 settings_manager.add_hidden_tag(tag)
91
90
92 def unhide(self, request):
91 def unhide(self, request):
93 """
92 """
94 Removed tag from user's hidden tags.
93 Removed tag from user's hidden tags.
95 """
94 """
96
95
97 tag = get_object_or_404(Tag, name=self.tag_name)
96 tag = get_object_or_404(Tag, name=self.tag_name)
98
97
99 settings_manager = get_settings_manager(request)
98 settings_manager = get_settings_manager(request)
100 settings_manager.del_hidden_tag(tag)
99 settings_manager.del_hidden_tag(tag)
General Comments 0
You need to be logged in to leave comments. Login now