landing.py
40 lines
| 1.3 KiB
| text/x-python
|
PythonLexer
|
r1740 | from datetime import datetime | ||
from datetime import timedelta | ||||
from django.db.models import Count | ||||
|
r1732 | from django.shortcuts import render | ||
from django.utils.decorators import method_decorator | ||||
from django.views.decorators.csrf import csrf_protect | ||||
|
r1740 | from boards import settings | ||
from boards.models import Post | ||||
|
r1745 | from boards.models import Tag, Attachment, STATUS_ACTIVE | ||
|
r1732 | 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(required=True)) | ||||
|
r1740 | |||
today = datetime.now() - timedelta(1) | ||||
|
r1745 | ops = Post.objects.filter(thread__replies__pub_time__gt=today, opening=True, thread__status=STATUS_ACTIVE)\ | ||
|
r1740 | .annotate(today_post_count=Count('thread__replies'))\ | ||
|
r1843 | .order_by('-pub_time') | ||
max_landing_threads = settings.get_int('View', 'MaxFavoriteThreads') | ||||
if max_landing_threads > 0: | ||||
ops = ops[:max_landing_threads] | ||||
|
r1740 | params[PARAM_LATEST_THREADS] = ops | ||
|
r1732 | return render(request, TEMPLATE, params) | ||