# HG changeset patch # User neko259 # Date 2016-12-26 18:54:06 # Node ID 69b1bc870cf675ffab4528e6c4e23b6e6d133a77 # Parent a7aa222d8fd79f973d190fc96ea8da0b4a26cda2 Show new and active threads for today (-24 hrs from now) at the landing page diff --git a/boards/config/default_settings.ini b/boards/config/default_settings.ini --- a/boards/config/default_settings.ini +++ b/boards/config/default_settings.ini @@ -32,6 +32,7 @@ ThreadsPerPage = 3 PostsPerPage = 10 ImagesPerPageGallery = 20 MaxFavoriteThreads = 20 +MaxLandingThreads = 20 [Storage] # Enable archiving threads instead of deletion when the thread limit is reached diff --git a/boards/templates/boards/landing.html b/boards/templates/boards/landing.html --- a/boards/templates/boards/landing.html +++ b/boards/templates/boards/landing.html @@ -26,7 +26,7 @@
{% for op in latest_threads %} - {{ op.get_link_view|safe }} {{ op.get_title_or_text }} ({{ op.thread.get_sections_str|safe }})
+ {{ op.get_link_view|safe }} {{ op.get_title_or_text }} ({{ op.thread.get_sections_str|safe }}) +{{ op.today_post_count }}
{% endfor %}
diff --git a/boards/views/landing.py b/boards/views/landing.py --- a/boards/views/landing.py +++ b/boards/views/landing.py @@ -1,10 +1,15 @@ +from datetime import datetime +from datetime import timedelta + +from django.db.models import Count from django.shortcuts import render from django.utils.decorators import method_decorator from django.views.decorators.csrf import csrf_protect +from boards import settings +from boards.models import Post +from boards.models import Tag, Attachment from boards.views.base import BaseBoardView -from boards.models import Tag, Post, Attachment - PARAM_SECTION_STR = 'section_str' PARAM_LATEST_THREADS = 'latest_threads' @@ -12,7 +17,6 @@ PARAM_IMAGES = 'images' TEMPLATE = 'boards/landing.html' -MAX_NEW_THREADS = 10 RANDOM_IMAGE_COUNT = 3 @@ -23,8 +27,14 @@ class LandingView(BaseBoardView): params[PARAM_SECTION_STR] = Tag.objects.get_tag_url_list( Tag.objects.filter(required=True)) - params[PARAM_LATEST_THREADS] = Post.objects.filter(opening=True)\ - .order_by('-pub_time')[:MAX_NEW_THREADS] + + today = datetime.now() - timedelta(1) + max_landing_threads = settings.get_int('View', 'MaxFavoriteThreads') + ops = Post.objects.filter(thread__replies__pub_time__gt=today, opening=True)\ + .annotate(today_post_count=Count('thread__replies'))\ + .order_by('-pub_time')[:max_landing_threads] + params[PARAM_LATEST_THREADS] = ops + params[PARAM_IMAGES] = Attachment.objects.get_random_images( RANDOM_IMAGE_COUNT)