Show More
@@ -5,7 +5,7 b' from boards.models.user import Notificat' | |||||
5 | __author__ = 'neko259' |
|
5 | __author__ = 'neko259' | |
6 |
|
6 | |||
7 | from boards import settings |
|
7 | from boards import settings | |
8 | from boards.models import Post, Tag |
|
8 | from boards.models import Post, Tag, Thread | |
9 |
|
9 | |||
10 | CONTEXT_SITE_NAME = 'site_name' |
|
10 | CONTEXT_SITE_NAME = 'site_name' | |
11 | CONTEXT_VERSION = 'version' |
|
11 | CONTEXT_VERSION = 'version' | |
@@ -20,6 +20,7 b" CONTEXT_TAGS_STR = 'tags_str'" | |||||
20 | CONTEXT_IMAGE_VIEWER = 'image_viewer' |
|
20 | CONTEXT_IMAGE_VIEWER = 'image_viewer' | |
21 | CONTEXT_HAS_FAV_THREADS = 'has_fav_threads' |
|
21 | CONTEXT_HAS_FAV_THREADS = 'has_fav_threads' | |
22 | CONTEXT_POW_DIFFICULTY = 'pow_difficulty' |
|
22 | CONTEXT_POW_DIFFICULTY = 'pow_difficulty' | |
|
23 | CONTEXT_NEW_POST_COUNT = 'new_post_count' | |||
23 |
|
24 | |||
24 |
|
25 | |||
25 | def get_notifications(context, request): |
|
26 | def get_notifications(context, request): | |
@@ -31,11 +32,23 b' def get_notifications(context, request):' | |||||
31 | SETTING_LAST_NOTIFICATION_ID) |
|
32 | SETTING_LAST_NOTIFICATION_ID) | |
32 |
|
33 | |||
33 | new_notifications_count = Notification.objects.get_notification_posts( |
|
34 | new_notifications_count = Notification.objects.get_notification_posts( | |
34 | usernames=usernames, last=last_notification_id).count() |
|
35 | usernames=usernames, last=last_notification_id).only('id').count() | |
35 | context[CONTEXT_NEW_NOTIFICATIONS_COUNT] = new_notifications_count |
|
36 | context[CONTEXT_NEW_NOTIFICATIONS_COUNT] = new_notifications_count | |
36 | context[CONTEXT_USERNAMES] = usernames |
|
37 | context[CONTEXT_USERNAMES] = usernames | |
37 |
|
38 | |||
38 |
|
39 | |||
|
40 | def get_new_post_count(context, request): | |||
|
41 | settings_manager = get_settings_manager(request) | |||
|
42 | fav_threads = settings_manager.get_fav_threads() | |||
|
43 | fav_thread_ops = Post.objects.filter(id__in=fav_threads.keys()) \ | |||
|
44 | .order_by('-pub_time').only('thread_id', 'pub_time') | |||
|
45 | ||||
|
46 | ops = [{'op': op, 'last_id': fav_threads[str(op.id)]} for op in fav_thread_ops] | |||
|
47 | count = Thread.objects.get_new_post_count(ops) | |||
|
48 | if count > 0: | |||
|
49 | context[CONTEXT_NEW_POST_COUNT] = '(+{})'.format(count) | |||
|
50 | ||||
|
51 | ||||
39 | def user_and_ui_processor(request): |
|
52 | def user_and_ui_processor(request): | |
40 | context = dict() |
|
53 | context = dict() | |
41 |
|
54 | |||
@@ -64,5 +77,6 b' def user_and_ui_processor(request):' | |||||
64 | len(settings_manager.get_fav_threads()) > 0 |
|
77 | len(settings_manager.get_fav_threads()) > 0 | |
65 |
|
78 | |||
66 | get_notifications(context, request) |
|
79 | get_notifications(context, request) | |
|
80 | get_new_post_count(context, request) | |||
67 |
|
81 | |||
68 | return context |
|
82 | return context |
@@ -163,6 +163,9 b' class Post(models.Model, Viewable):' | |||||
163 | def get_thread(self): |
|
163 | def get_thread(self): | |
164 | return self.thread |
|
164 | return self.thread | |
165 |
|
165 | |||
|
166 | def get_thread_id(self): | |||
|
167 | return self.thread_id | |||
|
168 | ||||
166 | def get_threads(self) -> QuerySet: |
|
169 | def get_threads(self) -> QuerySet: | |
167 | """ |
|
170 | """ | |
168 | Gets post's thread. |
|
171 | Gets post's thread. |
@@ -68,7 +68,7 b' class ThreadManager(models.Manager):' | |||||
68 | # TODO Use classes instead of dicts |
|
68 | # TODO Use classes instead of dicts | |
69 | for data in datas: |
|
69 | for data in datas: | |
70 | if data['last_id'] != FAV_THREAD_NO_UPDATES: |
|
70 | if data['last_id'] != FAV_THREAD_NO_UPDATES: | |
71 |
q = (Q(id=data['op'].get_thread() |
|
71 | q = (Q(id=data['op'].get_thread_id()) | |
72 | & Q(multi_replies__id__gt=data['last_id'])) |
|
72 | & Q(multi_replies__id__gt=data['last_id'])) | |
73 | if query is None: |
|
73 | if query is None: | |
74 | query = q |
|
74 | query = q |
@@ -141,10 +141,6 b' textarea, input {' | |||||
141 | margin: 1ex; |
|
141 | margin: 1ex; | |
142 | } |
|
142 | } | |
143 |
|
143 | |||
144 | #new-fav-post-count { |
|
|||
145 | display: none; |
|
|||
146 | } |
|
|||
147 |
|
||||
148 | .hidden_post { |
|
144 | .hidden_post { | |
149 | opacity: 0.2; |
|
145 | opacity: 0.2; | |
150 | } |
|
146 | } |
@@ -90,8 +90,6 b' function updateFavPosts() {' | |||||
90 | } |
|
90 | } | |
91 |
|
91 | |||
92 | function initFavPanel() { |
|
92 | function initFavPanel() { | |
93 | updateFavPosts(); |
|
|||
94 |
|
||||
95 | if ($('#fav-panel-btn').length > 0) { |
|
93 | if ($('#fav-panel-btn').length > 0) { | |
96 | setInterval(updateFavPosts, FAV_POST_UPDATE_PERIOD); |
|
94 | setInterval(updateFavPosts, FAV_POST_UPDATE_PERIOD); | |
97 | $('#fav-panel-btn').click(function() { |
|
95 | $('#fav-panel-btn').click(function() { |
@@ -40,7 +40,7 b'' | |||||
40 | <a href="{% url 'feed' %}" title="{% trans 'Feed' %}">{% trans 'feed' %}</a>, |
|
40 | <a href="{% url 'feed' %}" title="{% trans 'Feed' %}">{% trans 'feed' %}</a>, | |
41 | <a href="{% url 'random' %}" title="{% trans 'Random images' %}">{% trans 'random' %}</a>{% if has_fav_threads %}, |
|
41 | <a href="{% url 'random' %}" title="{% trans 'Random images' %}">{% trans 'random' %}</a>{% if has_fav_threads %}, | |
42 |
|
42 | |||
43 | <a href="#" id="fav-panel-btn">{% trans 'favorites' %} <span id="new-fav-post-count"></span></a> |
|
43 | <a href="#" id="fav-panel-btn">{% trans 'favorites' %} <span id="new-fav-post-count" {% if not new_post_count %}style="display: none" {% endif %}>{{ new_post_count }}</span></a> | |
44 | {% endif %} |
|
44 | {% endif %} | |
45 |
|
45 | |||
46 | {% if usernames %} |
|
46 | {% if usernames %} |
General Comments 0
You need to be logged in to leave comments.
Login now