##// END OF EJS Templates
Since we show sections on the landing page now, always show all tags in the tags view
Since we show sections on the landing page now, always show all tags in the tags view

File last commit:

r1740:69b1bc87 default
r1741:58ced8b0 default
Show More
landing.py
42 lines | 1.3 KiB | text/x-python | PythonLexer
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
PARAM_SECTION_STR = 'section_str'
PARAM_LATEST_THREADS = 'latest_threads'
PARAM_IMAGES = 'images'
TEMPLATE = 'boards/landing.html'
RANDOM_IMAGE_COUNT = 3
class LandingView(BaseBoardView):
@method_decorator(csrf_protect)
def get(self, request):
params = dict()
params[PARAM_SECTION_STR] = Tag.objects.get_tag_url_list(
Tag.objects.filter(required=True))
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)
return render(request, TEMPLATE, params)