diff --git a/boards/context_processors.py b/boards/context_processors.py --- a/boards/context_processors.py +++ b/boards/context_processors.py @@ -6,6 +6,8 @@ from boards import settings from boards.models import Post, Tag, Thread from boards.settings import SECTION_FORMS, SECTION_VIEW, SECTION_VERSION +PATTERN_NEW_POSTS_COUNT = '(+{})' + THEME_CSS = 'css/{}/base_page.css' CONTEXT_SITE_NAME = 'site_name' @@ -25,16 +27,20 @@ CONTEXT_BANNERS = 'banners' CONTEXT_ONLY_FAVORITES = 'only_favorites' -def get_notifications(context, settings_manager): +def get_notifications(context, settings_manager, fav_tags): usernames = settings_manager.get_notification_usernames() - fav_tags = settings_manager.get_fav_tags() + new_notifications_count = 0 + if usernames or fav_tags: last_notification_id = settings_manager.get_setting( SETTING_LAST_NOTIFICATION_ID) new_notifications_count = Notification.objects.get_notification_posts( - usernames=usernames, last=last_notification_id, user_settings=settings_manager.get_user_settings()).count() + usernames=usernames, + last=last_notification_id, + user_settings=settings_manager.get_user_settings()).count() + context[CONTEXT_NEW_NOTIFICATIONS_COUNT] = new_notifications_count context[CONTEXT_USERNAMES] = usernames @@ -43,7 +49,7 @@ def get_new_post_count(context, settings last_posts = settings_manager.get_last_posts() count = Thread.objects.get_new_post_count(last_posts) if count > 0: - context[CONTEXT_NEW_POST_COUNT] = '(+{})'.format(count) + context[CONTEXT_NEW_POST_COUNT] = PATTERN_NEW_POSTS_COUNT.format(count) def user_and_ui_processor(request): @@ -78,7 +84,7 @@ def user_and_ui_processor(request): context[CONTEXT_ONLY_FAVORITES] = settings_manager.get_setting( SETTING_ONLY_FAVORITES, default=False) - get_notifications(context, settings_manager) + get_notifications(context, settings_manager, fav_tags) get_new_post_count(context, settings_manager) return context