##// END OF EJS Templates
Slightly changed and optimized tag thread counters
neko259 -
r2087:1a07d841 default
parent child Browse files
Show More
@@ -1,162 +1,152 b''
1 {% extends "boards/paginated.html" %}
1 {% extends "boards/paginated.html" %}
2
2
3 {% load i18n %}
3 {% load i18n %}
4 {% load board %}
4 {% load board %}
5 {% load static %}
5 {% load static %}
6 {% load tz %}
6 {% load tz %}
7
7
8 {% block head %}
8 {% block head %}
9 <meta name="robots" content="noindex">
9 <meta name="robots" content="noindex">
10
10
11 {% if tag %}
11 {% if tag %}
12 <title>{{ tag.get_localized_name }} - {{ site_name }}</title>
12 <title>{{ tag.get_localized_name }} - {{ site_name }}</title>
13 {% else %}
13 {% else %}
14 <title>{{ site_name }}</title>
14 <title>{{ site_name }}</title>
15 {% endif %}
15 {% endif %}
16
16
17 {% if prev_page_link %}
17 {% if prev_page_link %}
18 <link rel="prev" href="{{ prev_page_link|safe }}" />
18 <link rel="prev" href="{{ prev_page_link|safe }}" />
19 {% endif %}
19 {% endif %}
20 {% if next_page_link %}
20 {% if next_page_link %}
21 <link rel="next" href="{{ next_page_link|safe }}" />
21 <link rel="next" href="{{ next_page_link|safe }}" />
22 {% endif %}
22 {% endif %}
23
23
24 {% endblock %}
24 {% endblock %}
25
25
26 {% block content %}
26 {% block content %}
27
27
28 {% get_current_language as LANGUAGE_CODE %}
28 {% get_current_language as LANGUAGE_CODE %}
29 {% get_current_timezone as TIME_ZONE %}
29 {% get_current_timezone as TIME_ZONE %}
30
30
31 {% for banner in banners %}
31 {% for banner in banners %}
32 <div class="post">
32 <div class="post">
33 <div class="title">{{ banner.title }}</div>
33 <div class="title">{{ banner.title }}</div>
34 <div>{{ banner.get_text|safe }}</div>
34 <div>{{ banner.get_text|safe }}</div>
35 <div>{% trans 'Details' %}: <a href="{{ banner.post.get_absolute_url|safe }}">>>{{ banner.post.id }}</a></div>
35 <div>{% trans 'Details' %}: <a href="{{ banner.post.get_absolute_url|safe }}">>>{{ banner.post.id }}</a></div>
36 </div>
36 </div>
37 {% endfor %}
37 {% endfor %}
38
38
39 {% if tag %}
39 {% if tag %}
40 <div class="tag_info" style="border: solid .5ex #{{ tag.get_color }}">
40 <div class="tag_info" style="border: solid .5ex #{{ tag.get_color }}">
41 {% if random_image_post %}
41 {% if random_image_post %}
42 <div class="tag-image">
42 <div class="tag-image">
43 {% with image=random_image_post.get_first_image %}
43 {% with image=random_image_post.get_first_image %}
44 <a href="{{ random_image_post.get_absolute_url|safe }}"><img
44 <a href="{{ random_image_post.get_absolute_url|safe }}"><img
45 src="{{ image.get_thumb_url|safe }}"
45 src="{{ image.get_thumb_url|safe }}"
46 width="{{ image.get_preview_size.0 }}"
46 width="{{ image.get_preview_size.0 }}"
47 height="{{ image.get_preview_size.1 }}"
47 height="{{ image.get_preview_size.1 }}"
48 alt="{{ random_image_post.id }}"/></a>
48 alt="{{ random_image_post.id }}"/></a>
49 {% endwith %}
49 {% endwith %}
50 </div>
50 </div>
51 {% endif %}
51 {% endif %}
52 <div class="tag-text-data">
52 <div class="tag-text-data">
53 <h2>
53 <h2>
54 /{{ tag.get_view|safe }}/
54 /{{ tag.get_view|safe }}/
55 </h2>
55 </h2>
56 {% if perms.change_tag %}
56 {% if perms.change_tag %}
57 <div class="moderator_info"><a href="{% url 'admin:boards_tag_change' tag.id %}">{% trans 'Edit tag' %}</a></div>
57 <div class="moderator_info"><a href="{% url 'admin:boards_tag_change' tag.id %}">{% trans 'Edit tag' %}</a></div>
58 {% endif %}
58 {% endif %}
59 <p>
59 <p>
60 <form action="{% url 'tag' tag.get_name %}" method="post" class="post-button-form">
60 <form action="{% url 'tag' tag.get_name %}" method="post" class="post-button-form">
61 {% if is_favorite %}
61 {% if is_favorite %}
62 <button name="method" value="unsubscribe" class="fav">β˜… {% trans "Remove from favorites" %}</button>
62 <button name="method" value="unsubscribe" class="fav">β˜… {% trans "Remove from favorites" %}</button>
63 {% else %}
63 {% else %}
64 <button name="method" value="subscribe" class="not_fav">β˜… {% trans "Add to favorites" %}</button>
64 <button name="method" value="subscribe" class="not_fav">β˜… {% trans "Add to favorites" %}</button>
65 {% endif %}
65 {% endif %}
66 </form>
66 </form>
67 &bull;
67 &bull;
68 <form action="{% url 'tag' tag.get_name %}" method="post" class="post-button-form">
68 <form action="{% url 'tag' tag.get_name %}" method="post" class="post-button-form">
69 {% if is_hidden %}
69 {% if is_hidden %}
70 <button name="method" value="unhide" class="fav">{% trans "Show" %}</button>
70 <button name="method" value="unhide" class="fav">{% trans "Show" %}</button>
71 {% else %}
71 {% else %}
72 <button name="method" value="hide" class="not_fav">{% trans "Hide" %}</button>
72 <button name="method" value="hide" class="not_fav">{% trans "Hide" %}</button>
73 {% endif %}
73 {% endif %}
74 </form>
74 </form>
75 &bull;
75 &bull;
76 <a href="{% url 'tag_gallery' tag.get_name %}">{% trans 'Gallery' %}</a>
76 <a href="{% url 'tag_gallery' tag.get_name %}">{% trans 'Gallery' %}</a>
77 </p>
77 </p>
78 {% if tag.get_description %}
78 {% if tag.get_description %}
79 <p>{{ tag.get_description|safe }}</p>
79 <p>{{ tag.get_description|safe }}</p>
80 {% endif %}
80 {% endif %}
81 <p>
81 <p>
82 {% with active_count=tag.get_active_thread_count bumplimit_count=tag.get_bumplimit_thread_count archived_count=tag.get_archived_thread_count %}
82 ● {{ tag_thread_count_active }} + {{ tag_thread_count_bumplimit }} + {{ tag_thread_count_archive }} = {{ tag_thread_count }}<br/>
83 {% if active_count %}
84 ● {{ active_count }}&ensp;
85 {% endif %}
86 {% if bumplimit_count %}
87 ◍ {{ bumplimit_count }}&ensp;
88 {% endif %}
89 {% if archived_count %}
90 β—‹ {{ archived_count }}&ensp;
91 {% endif %}
92 {% endwith %}
93 β™₯ {{ tag.get_post_count }}
83 β™₯ {{ tag.get_post_count }}
94 </p>
84 </p>
95 {% if tag.get_all_parents %}
85 {% if tag.get_all_parents %}
96 <p>
86 <p>
97 {% for parent in tag.get_all_parents %}
87 {% for parent in tag.get_all_parents %}
98 {{ parent.get_view|safe }} &gt;
88 {{ parent.get_view|safe }} &gt;
99 {% endfor %}
89 {% endfor %}
100 {{ tag.get_view|safe }}
90 {{ tag.get_view|safe }}
101 </p>
91 </p>
102 {% endif %}
92 {% endif %}
103 {% if tag.get_children.all %}
93 {% if tag.get_children.all %}
104 <p>
94 <p>
105 {% trans "Subsections: " %}
95 {% trans "Subsections: " %}
106 {% for child in tag.get_children.all %}
96 {% for child in tag.get_children.all %}
107 {{ child.get_view|safe }}{% if not forloop.last%}, {% endif %}
97 {{ child.get_view|safe }}{% if not forloop.last%}, {% endif %}
108 {% endfor %}
98 {% endfor %}
109 </p>
99 </p>
110 {% endif %}
100 {% endif %}
111 </div>
101 </div>
112 </div>
102 </div>
113 {% endif %}
103 {% endif %}
114
104
115 {% if threads %}
105 {% if threads %}
116 {% if prev_page_link %}
106 {% if prev_page_link %}
117 <div class="page_link">
107 <div class="page_link">
118 <a href="{{ prev_page_link }}">&lt;&lt; {% trans "Previous page" %} &lt;&lt;</a>
108 <a href="{{ prev_page_link }}">&lt;&lt; {% trans "Previous page" %} &lt;&lt;</a>
119 </div>
109 </div>
120 {% endif %}
110 {% endif %}
121
111
122 {% for thread in threads %}
112 {% for thread in threads %}
123 <div class="thread">
113 <div class="thread">
124 {% post_view thread.get_opening_post thread=thread truncated=True need_open_link=True %}
114 {% post_view thread.get_opening_post thread=thread truncated=True need_open_link=True %}
125 {% if not thread.archived %}
115 {% if not thread.archived %}
126 {% with last_replies=thread.get_last_replies %}
116 {% with last_replies=thread.get_last_replies %}
127 {% if last_replies %}
117 {% if last_replies %}
128 {% with skipped_replies_count=thread.get_skipped_replies_count %}
118 {% with skipped_replies_count=thread.get_skipped_replies_count %}
129 {% if skipped_replies_count %}
119 {% if skipped_replies_count %}
130 <div class="skipped_replies">
120 <div class="skipped_replies">
131 <a href="{% url 'thread' thread.get_opening_post_id %}">
121 <a href="{% url 'thread' thread.get_opening_post_id %}">
132 {% blocktrans count count=skipped_replies_count %}Skipped {{ count }} reply. Open thread to see all replies.{% plural %}Skipped {{ count }} replies. Open thread to see all replies.{% endblocktrans %}
122 {% blocktrans count count=skipped_replies_count %}Skipped {{ count }} reply. Open thread to see all replies.{% plural %}Skipped {{ count }} replies. Open thread to see all replies.{% endblocktrans %}
133 </a>
123 </a>
134 </div>
124 </div>
135 {% endif %}
125 {% endif %}
136 {% endwith %}
126 {% endwith %}
137 <div class="last-replies">
127 <div class="last-replies">
138 {% for post in last_replies %}
128 {% for post in last_replies %}
139 {% post_view post truncated=True %}
129 {% post_view post truncated=True %}
140 {% endfor %}
130 {% endfor %}
141 </div>
131 </div>
142 {% endif %}
132 {% endif %}
143 {% endwith %}
133 {% endwith %}
144 {% endif %}
134 {% endif %}
145 </div>
135 </div>
146 {% endfor %}
136 {% endfor %}
147
137
148 {% if next_page_link %}
138 {% if next_page_link %}
149 <div class="page_link">
139 <div class="page_link">
150 <a href="{{ next_page_link }}">&gt;&gt; {% trans "Next page" %} &gt;&gt;</a>
140 <a href="{{ next_page_link }}">&gt;&gt; {% trans "Next page" %} &gt;&gt;</a>
151 </div>
141 </div>
152 {% endif %}
142 {% endif %}
153 {% else %}
143 {% else %}
154 <div class="post">
144 <div class="post">
155 {% trans 'No threads exist. Create the first one!' %}</div>
145 {% trans 'No threads exist. Create the first one!' %}</div>
156 {% endif %}
146 {% endif %}
157
147
158 {% form_view form=form new_thread=True %}
148 {% form_view form=form new_thread=True %}
159
149
160 <script src="{% static 'js/thread_create.js' %}"></script>
150 <script src="{% static 'js/thread_create.js' %}"></script>
161
151
162 {% endblock %}
152 {% endblock %}
@@ -1,121 +1,135 b''
1 from django.shortcuts import get_object_or_404, redirect, get_list_or_404
1 from django.shortcuts import get_object_or_404, redirect, get_list_or_404
2 from django.urls import reverse
2 from django.urls import reverse
3
3
4 from boards.abstracts.settingsmanager import get_settings_manager, \
4 from boards.abstracts.settingsmanager import get_settings_manager, \
5 SETTING_FAVORITE_TAGS, SETTING_HIDDEN_TAGS
5 SETTING_FAVORITE_TAGS, SETTING_HIDDEN_TAGS
6 from boards.models import Tag, TagAlias, Post
6 from boards.models import Tag, TagAlias, Post
7 from boards.views.all_threads import AllThreadsView
7 from boards.views.all_threads import AllThreadsView
8 from boards.views.mixins import DispatcherMixin, PARAMETER_METHOD
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'
12 PARAM_TAG = 'tag'
12 PARAM_TAG = 'tag'
13 PARAM_IS_FAVORITE = 'is_favorite'
13 PARAM_IS_FAVORITE = 'is_favorite'
14 PARAM_IS_HIDDEN = 'is_hidden'
14 PARAM_IS_HIDDEN = 'is_hidden'
15 PARAM_RANDOM_IMAGE_POST = 'random_image_post'
15 PARAM_RANDOM_IMAGE_POST = 'random_image_post'
16 PARAM_RELATED_TAGS = 'related_tags'
16 PARAM_RELATED_TAGS = 'related_tags'
17 PARAM_THREAD_COUNT = 'tag_thread_count'
18 PARAM_THREAD_COUNT_ACTIVE = 'tag_thread_count_active'
19 PARAM_THREAD_COUNT_BUMPLIMIT = 'tag_thread_count_bumplimit'
20 PARAM_THREAD_COUNT_ARCHIVE = 'tag_thread_count_archive'
17
21
18
22
19 __author__ = 'neko259'
23 __author__ = 'neko259'
20
24
21
25
22 class TagView(AllThreadsView, DispatcherMixin):
26 class TagView(AllThreadsView, DispatcherMixin):
23
27
24 tag_name = None
28 tag_name = None
25
29
26 def get_threads(self):
30 def get_threads(self):
27 tag_alias = get_object_or_404(TagAlias, name=self.tag_name)
31 tag_alias = get_object_or_404(TagAlias, name=self.tag_name)
28 tag = tag_alias.parent
32 tag = tag_alias.parent
29
33
30 hidden_tags = list(self.settings_manager.get_hidden_tags())
34 hidden_tags = list(self.settings_manager.get_hidden_tags())
31
35
32 try:
36 try:
33 hidden_tags.remove(tag)
37 hidden_tags.remove(tag)
34 except ValueError:
38 except ValueError:
35 pass
39 pass
36
40
37 return tag.get_threads().exclude(
41 return tag.get_threads().exclude(
38 tags__in=hidden_tags)
42 tags__in=hidden_tags)
39
43
40 def get_context_data(self, **kwargs):
44 def get_context_data(self, **kwargs):
41 params = super(TagView, self).get_context_data(**kwargs)
45 params = super(TagView, self).get_context_data(**kwargs)
42
46
43 settings_manager = get_settings_manager(kwargs['request'])
47 settings_manager = get_settings_manager(kwargs['request'])
44
48
45 tag_alias = get_list_or_404(TagAlias, name=self.tag_name)[0]
49 tag_alias = get_list_or_404(TagAlias, name=self.tag_name)[0]
46 tag = tag_alias.parent
50 tag = tag_alias.parent
47 params[PARAM_TAG] = tag
51 params[PARAM_TAG] = tag
48
52
49 params[PARAM_IS_FAVORITE] = settings_manager.tag_is_fav(tag)
53 params[PARAM_IS_FAVORITE] = settings_manager.tag_is_fav(tag)
50 params[PARAM_IS_HIDDEN] = settings_manager.tag_is_hidden(tag)
54 params[PARAM_IS_HIDDEN] = settings_manager.tag_is_hidden(tag)
51
55
52 params[PARAM_RANDOM_IMAGE_POST] = tag.get_random_image_post()
56 params[PARAM_RANDOM_IMAGE_POST] = tag.get_random_image_post()
53 params[PARAM_RELATED_TAGS] = tag.get_related_tags()
57 params[PARAM_RELATED_TAGS] = tag.get_related_tags()
54
58
59 active_count = tag.get_active_thread_count()
60 bumplimit_count = tag.get_bumplimit_thread_count()
61 archive_count = tag.get_archived_thread_count()
62 total_count = active_count + bumplimit_count + archive_count
63
64 params[PARAM_THREAD_COUNT_ACTIVE] = active_count
65 params[PARAM_THREAD_COUNT_BUMPLIMIT] = bumplimit_count
66 params[PARAM_THREAD_COUNT_ARCHIVE] = archive_count
67 params[PARAM_THREAD_COUNT] = total_count
68
55 return params
69 return params
56
70
57 def get_reverse_url(self):
71 def get_reverse_url(self):
58 return reverse('tag', kwargs={'tag_name': self.tag_name})
72 return reverse('tag', kwargs={'tag_name': self.tag_name})
59
73
60 def get(self, request, tag_name, form=None):
74 def get(self, request, tag_name, form=None):
61 self.tag_name = tag_name
75 self.tag_name = tag_name
62
76
63 return super(TagView, self).get(request, form)
77 return super(TagView, self).get(request, form)
64
78
65
79
66 def post(self, request, tag_name):
80 def post(self, request, tag_name):
67 self.tag_name = tag_name
81 self.tag_name = tag_name
68
82
69 if PARAMETER_METHOD in request.POST:
83 if PARAMETER_METHOD in request.POST:
70 self.dispatch_method(request)
84 self.dispatch_method(request)
71
85
72 return redirect('tag', tag_name)
86 return redirect('tag', tag_name)
73 else:
87 else:
74 form = ThreadForm(request.POST, request.FILES,
88 form = ThreadForm(request.POST, request.FILES,
75 error_class=PlainErrorList,
89 error_class=PlainErrorList,
76 session=request.session)
90 session=request.session)
77
91
78 if form.is_valid():
92 if form.is_valid():
79 return Post.objects.create_from_form(request, form, opening_post=None)
93 return Post.objects.create_from_form(request, form, opening_post=None)
80 if form.need_to_ban:
94 if form.need_to_ban:
81 # Ban user because he is suspected to be a bot
95 # Ban user because he is suspected to be a bot
82 self._ban_current_user(request)
96 self._ban_current_user(request)
83
97
84 return self.get(request, tag_name, form)
98 return self.get(request, tag_name, form)
85
99
86 def subscribe(self, request):
100 def subscribe(self, request):
87 alias = get_object_or_404(TagAlias, name=self.tag_name)
101 alias = get_object_or_404(TagAlias, name=self.tag_name)
88 tag = alias.parent
102 tag = alias.parent
89
103
90 settings_manager = get_settings_manager(request)
104 settings_manager = get_settings_manager(request)
91 settings_manager.add_fav_tag(tag)
105 settings_manager.add_fav_tag(tag)
92
106
93 def unsubscribe(self, request):
107 def unsubscribe(self, request):
94 alias = get_object_or_404(TagAlias, name=self.tag_name)
108 alias = get_object_or_404(TagAlias, name=self.tag_name)
95 tag = alias.parent
109 tag = alias.parent
96
110
97 settings_manager = get_settings_manager(request)
111 settings_manager = get_settings_manager(request)
98 settings_manager.del_fav_tag(tag)
112 settings_manager.del_fav_tag(tag)
99
113
100 def hide(self, request):
114 def hide(self, request):
101 """
115 """
102 Adds tag to user's hidden tags. Threads with this tag will not be
116 Adds tag to user's hidden tags. Threads with this tag will not be
103 shown.
117 shown.
104 """
118 """
105
119
106 alias = get_object_or_404(TagAlias, name=self.tag_name)
120 alias = get_object_or_404(TagAlias, name=self.tag_name)
107 tag = alias.parent
121 tag = alias.parent
108
122
109 settings_manager = get_settings_manager(request)
123 settings_manager = get_settings_manager(request)
110 settings_manager.add_hidden_tag(tag)
124 settings_manager.add_hidden_tag(tag)
111
125
112 def unhide(self, request):
126 def unhide(self, request):
113 """
127 """
114 Removed tag from user's hidden tags.
128 Removed tag from user's hidden tags.
115 """
129 """
116
130
117 alias = get_object_or_404(TagAlias, name=self.tag_name)
131 alias = get_object_or_404(TagAlias, name=self.tag_name)
118 tag = alias.parent
132 tag = alias.parent
119
133
120 settings_manager = get_settings_manager(request)
134 settings_manager = get_settings_manager(request)
121 settings_manager.del_hidden_tag(tag)
135 settings_manager.del_hidden_tag(tag)
General Comments 0
You need to be logged in to leave comments. Login now