##// END OF EJS Templates
Show only favorite tags' content in the landing page if 'only favorite' option is enabled
neko259 -
r2125:83d379e2 default
parent child Browse files
Show More
@@ -10,6 +10,8 from boards import settings
10 10 from boards.models import Post, Tag, STATUS_ACTIVE, TagAlias
11 11 from boards.settings import SECTION_VIEW
12 12 from boards.views.base import BaseBoardView
13 from boards.abstracts.settingsmanager import get_settings_manager,\
14 SETTING_ONLY_FAVORITES
13 15
14 16 PARAM_SECTION_STR = 'section_str'
15 17 PARAM_LATEST_THREADS = 'latest_threads'
@@ -28,10 +30,16 class LandingView(BaseBoardView):
28 30 .order_by('aliases__name'))
29 31
30 32 today = datetime.now() - timedelta(1)
31 ops = Post.objects.filter(thread__replies__pub_time__gt=today, opening=True, thread__status=STATUS_ACTIVE)\
32 .annotate(today_post_count=Count('thread__replies'))\
33 ops = Post.objects.filter(thread__replies__pub_time__gt=today, opening=True, thread__status=STATUS_ACTIVE)
34
35 fav_tags = self._get_fav_tags(request)
36 if len(fav_tags) > 0:
37 ops = ops.filter(thread__tags__in=fav_tags)
38
39 ops = ops.annotate(today_post_count=Count('thread__replies'))\
33 40 .order_by('-pub_time')
34 41
42
35 43 max_landing_threads = settings.get_int(SECTION_VIEW, 'MaxLandingThreads')
36 44 if max_landing_threads > 0:
37 45 ops = ops[:max_landing_threads]
@@ -39,8 +47,17 class LandingView(BaseBoardView):
39 47 params[PARAM_LATEST_THREADS] = ops
40 48
41 49 max_landing_posts = settings.get_int(SECTION_VIEW, 'MaxLandingPosts')
42 params[PARAM_LATEST_POSTS] = Post.objects.filter(pub_time__gt=today)\
50 latest_posts = Post.objects.filter(pub_time__gt=today)
51 if len(fav_tags) > 0:
52 latest_posts = latest_posts.filter(thread__tags__in=fav_tags)
53 params[PARAM_LATEST_POSTS] = latest_posts\
43 54 .order_by('-pub_time')[:max_landing_posts]
44 55
45 56 return render(request, TEMPLATE, params)
46 57
58 def _get_fav_tags(self, request):
59 fav_tags = []
60 settings_manager = get_settings_manager(request)
61 if settings_manager.get_setting(SETTING_ONLY_FAVORITES):
62 fav_tags = settings_manager.get_fav_tags()
63 return fav_tags
General Comments 0
You need to be logged in to leave comments. Login now