landing.py
32 lines
| 940 B
| text/x-python
|
PythonLexer
neko259
|
r1732 | from django.shortcuts import render | ||
from django.utils.decorators import method_decorator | ||||
from django.views.decorators.csrf import csrf_protect | ||||
from boards.views.base import BaseBoardView | ||||
from boards.models import Tag, Post, Attachment | ||||
PARAM_SECTION_STR = 'section_str' | ||||
PARAM_LATEST_THREADS = 'latest_threads' | ||||
PARAM_IMAGES = 'images' | ||||
TEMPLATE = 'boards/landing.html' | ||||
MAX_NEW_THREADS = 10 | ||||
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)) | ||||
params[PARAM_LATEST_THREADS] = Post.objects.filter(opening=True)\ | ||||
.order_by('-pub_time')[:MAX_NEW_THREADS] | ||||
params[PARAM_IMAGES] = Attachment.objects.get_random_images( | ||||
RANDOM_IMAGE_COUNT) | ||||
return render(request, TEMPLATE, params) | ||||