# HG changeset patch # User neko259 # Date 2018-12-04 16:30:13 # Node ID 83d379e2791f26300de00cb291ea51e6d51f4cc4 # Parent 181844449f63aa53d8c26121ef59e9db9afc68c1 Show only favorite tags' content in the landing page if 'only favorite' option is enabled diff --git a/boards/views/landing.py b/boards/views/landing.py --- a/boards/views/landing.py +++ b/boards/views/landing.py @@ -10,6 +10,8 @@ from boards import settings from boards.models import Post, Tag, STATUS_ACTIVE, TagAlias from boards.settings import SECTION_VIEW from boards.views.base import BaseBoardView +from boards.abstracts.settingsmanager import get_settings_manager,\ + SETTING_ONLY_FAVORITES PARAM_SECTION_STR = 'section_str' PARAM_LATEST_THREADS = 'latest_threads' @@ -28,9 +30,15 @@ class LandingView(BaseBoardView): .order_by('aliases__name')) today = datetime.now() - timedelta(1) - ops = Post.objects.filter(thread__replies__pub_time__gt=today, opening=True, thread__status=STATUS_ACTIVE)\ - .annotate(today_post_count=Count('thread__replies'))\ - .order_by('-pub_time') + ops = Post.objects.filter(thread__replies__pub_time__gt=today, opening=True, thread__status=STATUS_ACTIVE) + + fav_tags = self._get_fav_tags(request) + if len(fav_tags) > 0: + ops = ops.filter(thread__tags__in=fav_tags) + + ops = ops.annotate(today_post_count=Count('thread__replies'))\ + .order_by('-pub_time') + max_landing_threads = settings.get_int(SECTION_VIEW, 'MaxLandingThreads') if max_landing_threads > 0: @@ -39,8 +47,17 @@ class LandingView(BaseBoardView): params[PARAM_LATEST_THREADS] = ops max_landing_posts = settings.get_int(SECTION_VIEW, 'MaxLandingPosts') - params[PARAM_LATEST_POSTS] = Post.objects.filter(pub_time__gt=today)\ + latest_posts = Post.objects.filter(pub_time__gt=today) + if len(fav_tags) > 0: + latest_posts = latest_posts.filter(thread__tags__in=fav_tags) + params[PARAM_LATEST_POSTS] = latest_posts\ .order_by('-pub_time')[:max_landing_posts] return render(request, TEMPLATE, params) + def _get_fav_tags(self, request): + fav_tags = [] + settings_manager = get_settings_manager(request) + if settings_manager.get_setting(SETTING_ONLY_FAVORITES): + fav_tags = settings_manager.get_fav_tags() + return fav_tags