Show More
@@ -19,6 +19,11 b' from boards.models.post.export import ge' | |||||
19 | from boards.models.post.manager import PostManager |
|
19 | from boards.models.post.manager import PostManager | |
20 | from boards.models.user import Notification |
|
20 | from boards.models.user import Notification | |
21 |
|
21 | |||
|
22 | CSS_CLS_HIDDEN_POST = 'hidden_post' | |||
|
23 | CSS_CLS_DEAD_POST = 'dead_post' | |||
|
24 | CSS_CLS_ARCHIVE_POST = 'archive_post' | |||
|
25 | CSS_CLS_POST = 'post' | |||
|
26 | ||||
22 | TITLE_MAX_WORDS = 10 |
|
27 | TITLE_MAX_WORDS = 10 | |
23 |
|
28 | |||
24 | APP_LABEL_BOARDS = 'boards' |
|
29 | APP_LABEL_BOARDS = 'boards' | |
@@ -94,6 +99,7 b' class Post(models.Model, Viewable):' | |||||
94 |
|
99 | |||
95 | tripcode = models.CharField(max_length=50, null=True) |
|
100 | tripcode = models.CharField(max_length=50, null=True) | |
96 | opening = models.BooleanField() |
|
101 | opening = models.BooleanField() | |
|
102 | hidden = models.BooleanField(default=False) | |||
97 |
|
103 | |||
98 | def __str__(self): |
|
104 | def __str__(self): | |
99 | return 'P#{}/{}'.format(self.id, self.get_title()) |
|
105 | return 'P#{}/{}'.format(self.id, self.get_title()) | |
@@ -172,11 +178,13 b' class Post(models.Model, Viewable):' | |||||
172 |
|
178 | |||
173 | thread = self.get_thread() |
|
179 | thread = self.get_thread() | |
174 |
|
180 | |||
175 |
css_class = |
|
181 | css_classes = [CSS_CLS_POST] | |
176 | if thread.archived: |
|
182 | if thread.archived: | |
177 | css_class += ' archive_post' |
|
183 | css_classes.append(CSS_CLS_ARCHIVE_POST) | |
178 | elif not thread.can_bump(): |
|
184 | elif not thread.can_bump(): | |
179 | css_class += ' dead_post' |
|
185 | css_classes.append(CSS_CLS_DEAD_POST) | |
|
186 | if self.is_hidden(): | |||
|
187 | css_classes.append(CSS_CLS_HIDDEN_POST) | |||
180 |
|
188 | |||
181 | params = dict() |
|
189 | params = dict() | |
182 | for param in POST_VIEW_PARAMS: |
|
190 | for param in POST_VIEW_PARAMS: | |
@@ -187,7 +195,7 b' class Post(models.Model, Viewable):' | |||||
187 | PARAMETER_POST: self, |
|
195 | PARAMETER_POST: self, | |
188 | PARAMETER_IS_OPENING: self.is_opening(), |
|
196 | PARAMETER_IS_OPENING: self.is_opening(), | |
189 | PARAMETER_THREAD: thread, |
|
197 | PARAMETER_THREAD: thread, | |
190 | PARAMETER_CSS_CLASS: css_class, |
|
198 | PARAMETER_CSS_CLASS: ' '.join(css_classes), | |
191 | }) |
|
199 | }) | |
192 |
|
200 | |||
193 | return render_to_string('boards/post.html', params) |
|
201 | return render_to_string('boards/post.html', params) | |
@@ -345,3 +353,9 b' class Post(models.Model, Viewable):' | |||||
345 | result = '<b>{}</b>'.format(result) |
|
353 | result = '<b>{}</b>'.format(result) | |
346 |
|
354 | |||
347 | return result |
|
355 | return result | |
|
356 | ||||
|
357 | def is_hidden(self) -> bool: | |||
|
358 | return self.hidden | |||
|
359 | ||||
|
360 | def set_hidden(self, hidden): | |||
|
361 | self.hidden = hidden |
@@ -142,4 +142,12 b' textarea, input {' | |||||
142 |
|
142 | |||
143 | #new-fav-post-count { |
|
143 | #new-fav-post-count { | |
144 | display: none; |
|
144 | display: none; | |
145 | } No newline at end of file |
|
145 | } | |
|
146 | ||||
|
147 | .hidden_post { | |||
|
148 | opacity: 0.2; | |||
|
149 | } | |||
|
150 | ||||
|
151 | .hidden_post:hover { | |||
|
152 | opacity: 1; | |||
|
153 | } |
@@ -51,6 +51,10 b'' | |||||
51 | {% if is_opening %} |
|
51 | {% if is_opening %} | |
52 | | <a href="{% url 'admin:boards_thread_change' thread.id %}">{% trans 'Edit thread' %}</a> |
|
52 | | <a href="{% url 'admin:boards_thread_change' thread.id %}">{% trans 'Edit thread' %}</a> | |
53 | {% endif %} |
|
53 | {% endif %} | |
|
54 | <form action="{% url 'thread' thread.get_opening_post_id %}?post_id={{ post.id }}" method="post" class="post-button-form"> | |||
|
55 | | <button name="method" value="toggle_hide_post">H</button> | |||
|
56 | </form> | |||
|
57 | </form> | |||
54 | </span> |
|
58 | </span> | |
55 | {% endif %} |
|
59 | {% endif %} | |
56 | </div> |
|
60 | </div> |
@@ -8,9 +8,14 b' class DispatcherMixin:' | |||||
8 | 'method' request parameter. |
|
8 | 'method' request parameter. | |
9 | """ |
|
9 | """ | |
10 |
|
10 | |||
|
11 | def __init__(self): | |||
|
12 | self.user = None | |||
|
13 | ||||
11 | def dispatch_method(self, *args, **kwargs): |
|
14 | def dispatch_method(self, *args, **kwargs): | |
12 | request = args[0] |
|
15 | request = args[0] | |
13 |
|
16 | |||
|
17 | self.user = request.user | |||
|
18 | ||||
14 | method_name = None |
|
19 | method_name = None | |
15 | if PARAMETER_METHOD in request.GET: |
|
20 | if PARAMETER_METHOD in request.GET: | |
16 | method_name = request.GET[PARAMETER_METHOD] |
|
21 | method_name = request.GET[PARAMETER_METHOD] |
@@ -5,7 +5,7 b' from boards.abstracts.settingsmanager im' | |||||
5 | SETTING_FAVORITE_TAGS, SETTING_HIDDEN_TAGS |
|
5 | SETTING_FAVORITE_TAGS, SETTING_HIDDEN_TAGS | |
6 | from boards.models import Tag, PostImage |
|
6 | from boards.models import Tag, PostImage | |
7 | from boards.views.all_threads import AllThreadsView, DEFAULT_PAGE |
|
7 | from boards.views.all_threads import AllThreadsView, DEFAULT_PAGE | |
8 | from boards.views.mixins import DispatcherMixin |
|
8 | from boards.views.mixins import DispatcherMixin, PARAMETER_METHOD | |
9 | from boards.forms import ThreadForm, PlainErrorList |
|
9 | from boards.forms import ThreadForm, PlainErrorList | |
10 |
|
10 | |||
11 | PARAM_HIDDEN_TAGS = 'hidden_tags' |
|
11 | PARAM_HIDDEN_TAGS = 'hidden_tags' | |
@@ -74,9 +74,8 b' class TagView(AllThreadsView, Dispatcher' | |||||
74 | def post(self, request, tag_name): |
|
74 | def post(self, request, tag_name): | |
75 | self.tag_name = tag_name |
|
75 | self.tag_name = tag_name | |
76 |
|
76 | |||
77 |
if |
|
77 | if PARAMETER_METHOD in request.POST: | |
78 | self.dispatch_method(request) |
|
78 | self.dispatch_method(request) | |
79 | form = None |
|
|||
80 |
|
79 | |||
81 | return redirect('tag', tag_name) |
|
80 | return redirect('tag', tag_name) | |
82 | else: |
|
81 | else: |
@@ -1,4 +1,5 b'' | |||||
1 | import hashlib |
|
1 | from django.contrib.auth.decorators import permission_required | |
|
2 | ||||
2 | from django.core.exceptions import ObjectDoesNotExist |
|
3 | from django.core.exceptions import ObjectDoesNotExist | |
3 | from django.http import Http404 |
|
4 | from django.http import Http404 | |
4 | from django.shortcuts import get_object_or_404, render, redirect |
|
5 | from django.shortcuts import get_object_or_404, render, redirect | |
@@ -11,11 +12,11 b' from boards.abstracts.settingsmanager im' | |||||
11 | from boards.forms import PostForm, PlainErrorList |
|
12 | from boards.forms import PostForm, PlainErrorList | |
12 | from boards.models import Post |
|
13 | from boards.models import Post | |
13 | from boards.views.base import BaseBoardView, CONTEXT_FORM |
|
14 | from boards.views.base import BaseBoardView, CONTEXT_FORM | |
14 | from boards.views.mixins import DispatcherMixin |
|
15 | from boards.views.mixins import DispatcherMixin, PARAMETER_METHOD | |
15 | from boards.views.posting_mixin import PostMixin |
|
16 | from boards.views.posting_mixin import PostMixin | |
16 |
|
||||
17 | import neboard |
|
17 | import neboard | |
18 |
|
18 | |||
|
19 | REQ_POST_ID = 'post_id' | |||
19 |
|
20 | |||
20 | CONTEXT_LASTUPDATE = "last_update" |
|
21 | CONTEXT_LASTUPDATE = "last_update" | |
21 | CONTEXT_THREAD = 'thread' |
|
22 | CONTEXT_THREAD = 'thread' | |
@@ -88,7 +89,7 b' class ThreadView(BaseBoardView, PostMixi' | |||||
88 | if not opening_post.is_opening(): |
|
89 | if not opening_post.is_opening(): | |
89 | raise Http404 |
|
90 | raise Http404 | |
90 |
|
91 | |||
91 |
if |
|
92 | if PARAMETER_METHOD in request.POST: | |
92 | self.dispatch_method(request, opening_post) |
|
93 | self.dispatch_method(request, opening_post) | |
93 |
|
94 | |||
94 | return redirect('thread', post_id) # FIXME Different for different modes |
|
95 | return redirect('thread', post_id) # FIXME Different for different modes | |
@@ -161,3 +162,12 b' class ThreadView(BaseBoardView, PostMixi' | |||||
161 | def unsubscribe(self, request, opening_post): |
|
162 | def unsubscribe(self, request, opening_post): | |
162 | settings_manager = get_settings_manager(request) |
|
163 | settings_manager = get_settings_manager(request) | |
163 | settings_manager.del_fav_thread(opening_post) |
|
164 | settings_manager.del_fav_thread(opening_post) | |
|
165 | ||||
|
166 | @permission_required('boards.post_hide_unhide') | |||
|
167 | def toggle_hide_post(self, request, opening_post): | |||
|
168 | post_id = request.GET.get(REQ_POST_ID) | |||
|
169 | ||||
|
170 | if post_id: | |||
|
171 | post = get_object_or_404(Post, id=post_id) | |||
|
172 | post.set_hidden(not post.is_hidden()) | |||
|
173 | post.save(update_fields=['hidden']) |
General Comments 0
You need to be logged in to leave comments.
Login now