##// END OF EJS Templates
Unify thread and post creation into one method inside post manager, that can be called from almost anywhere (one step closer to ajax thread creation)
Unify thread and post creation into one method inside post manager, that can be called from almost anywhere (one step closer to ajax thread creation)

File last commit:

r1905:c3c10de6 default
r1997:be673d04 default
Show More
landing.py
41 lines | 1.4 KiB | text/x-python | PythonLexer
from datetime import datetime
from datetime import timedelta
from django.db.models import Count, Q
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, Tag, Attachment, STATUS_ACTIVE, TagAlias
from boards.models.tag import DEFAULT_LOCALE
from boards.views.base import BaseBoardView
PARAM_SECTION_STR = 'section_str'
PARAM_LATEST_THREADS = 'latest_threads'
TEMPLATE = 'boards/landing.html'
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(Q(aliases__in=TagAlias.objects.filter_localized()) & Q(required=True))
.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')
max_landing_threads = settings.get_int('View', 'MaxFavoriteThreads')
if max_landing_threads > 0:
ops = ops[:max_landing_threads]
params[PARAM_LATEST_THREADS] = ops
return render(request, TEMPLATE, params)