##// 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 b' from boards import settings'
10 from boards.models import Post, Tag, STATUS_ACTIVE, TagAlias
10 from boards.models import Post, Tag, STATUS_ACTIVE, TagAlias
11 from boards.settings import SECTION_VIEW
11 from boards.settings import SECTION_VIEW
12 from boards.views.base import BaseBoardView
12 from boards.views.base import BaseBoardView
13 from boards.abstracts.settingsmanager import get_settings_manager,\
14 SETTING_ONLY_FAVORITES
13
15
14 PARAM_SECTION_STR = 'section_str'
16 PARAM_SECTION_STR = 'section_str'
15 PARAM_LATEST_THREADS = 'latest_threads'
17 PARAM_LATEST_THREADS = 'latest_threads'
@@ -28,9 +30,15 b' class LandingView(BaseBoardView):'
28 .order_by('aliases__name'))
30 .order_by('aliases__name'))
29
31
30 today = datetime.now() - timedelta(1)
32 today = datetime.now() - timedelta(1)
31 ops = Post.objects.filter(thread__replies__pub_time__gt=today, opening=True, thread__status=STATUS_ACTIVE)\
33 ops = Post.objects.filter(thread__replies__pub_time__gt=today, opening=True, thread__status=STATUS_ACTIVE)
32 .annotate(today_post_count=Count('thread__replies'))\
34
33 .order_by('-pub_time')
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'))\
40 .order_by('-pub_time')
41
34
42
35 max_landing_threads = settings.get_int(SECTION_VIEW, 'MaxLandingThreads')
43 max_landing_threads = settings.get_int(SECTION_VIEW, 'MaxLandingThreads')
36 if max_landing_threads > 0:
44 if max_landing_threads > 0:
@@ -39,8 +47,17 b' class LandingView(BaseBoardView):'
39 params[PARAM_LATEST_THREADS] = ops
47 params[PARAM_LATEST_THREADS] = ops
40
48
41 max_landing_posts = settings.get_int(SECTION_VIEW, 'MaxLandingPosts')
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 .order_by('-pub_time')[:max_landing_posts]
54 .order_by('-pub_time')[:max_landing_posts]
44
55
45 return render(request, TEMPLATE, params)
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