##// END OF EJS Templates
Add notifications for threads created in favorite tags
neko259 -
r2054:fca209ed default
parent child Browse files
Show More
@@ -27,13 +27,14 b" CONTEXT_ONLY_FAVORITES = 'only_favorites"
27 27
28 28 def get_notifications(context, settings_manager):
29 29 usernames = settings_manager.get_notification_usernames()
30 fav_tags = settings_manager.get_fav_tags()
30 31 new_notifications_count = 0
31 if usernames:
32 if usernames or fav_tags:
32 33 last_notification_id = settings_manager.get_setting(
33 34 SETTING_LAST_NOTIFICATION_ID)
34 35
35 36 new_notifications_count = Notification.objects.get_notification_posts(
36 usernames=usernames, last=last_notification_id).only('id').count()
37 usernames=usernames, last=last_notification_id, fav_tags=fav_tags).only('id').count()
37 38 context[CONTEXT_NEW_NOTIFICATIONS_COUNT] = new_notifications_count
38 39 context[CONTEXT_USERNAMES] = usernames
39 40
@@ -1,4 +1,5 b''
1 1 from django.db import models
2 from django.db.models import Q
2 3 import boards
3 4
4 5 __author__ = 'neko259'
@@ -24,10 +25,10 b' class Ban(models.Model):'
24 25
25 26
26 27 class NotificationManager(models.Manager):
27 def get_notification_posts(self, usernames: list, last: int = None):
28 def get_notification_posts(self, usernames: list, last: int = None, fav_tags=None):
28 29 lower_names = [username.lower() for username in usernames]
29 30 posts = boards.models.post.Post.objects.filter(
30 notification__name__in=lower_names).distinct()
31 Q(notification__name__in=lower_names) | Q(thread__tags__in=fav_tags)).distinct()
31 32 if last is not None:
32 33 posts = posts.filter(id__gt=last)
33 34 posts = posts.order_by('-id')
@@ -57,7 +57,7 b''
57 57 <a href="{% url 'feed' %}?favorites" id="fav-panel-btn">{% trans 'favorites' %} <span id="new-fav-post-count" {% if not new_post_count %}style="display: none" {% endif %}>{{ new_post_count|safe }}</span></a>
58 58 {% endif %}
59 59
60 {% if usernames %}
60 {% if usernames or tags_str %}
61 61 <a class="right-link link" href="{% url 'notifications' %}" title="{% trans 'Notifications' %}">
62 62 {% trans 'Notifications' %}
63 63 {% ifnotequal new_notifications_count 0 %}
@@ -27,8 +27,10 b' class NotificationView(BaseBoardView):'
27 27 else:
28 28 notification_usernames = [username]
29 29
30 fav_tags = settings_manager.get_fav_tags()
31
30 32 posts = Notification.objects.get_notification_posts(
31 usernames=notification_usernames)
33 usernames=notification_usernames, fav_tags=fav_tags)
32 34
33 35 if username is None:
34 36 last = posts.first()
General Comments 0
You need to be logged in to leave comments. Login now