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