You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
1.1 KiB
36 lines
1.1 KiB
from django.shortcuts import render, get_object_or_404 |
|
from django.http import HttpResponse |
|
|
|
from .models import Post |
|
from comments.models import Comment |
|
|
|
from comments import services as comments_services |
|
|
|
|
|
def index(request): |
|
"""Список постов.""" |
|
post_list = Post.objects.order_by("-pub_date")[:20] |
|
return render(request, "posts/index.html", {"posts": post_list}) |
|
|
|
|
|
def detail(request, post_id): |
|
"""Страница с просмотром поста.""" |
|
# вынести отсюда все. Также надо обработать текст поста тут. |
|
|
|
post = get_object_or_404(Post, pk=post_id) |
|
comments = post.comment_set.all() |
|
comments_count = comments.count() |
|
|
|
_nickname = request.COOKIES.get("nickname") |
|
nickname = comments_services.decode_nickname(_nickname) if _nickname else "" |
|
|
|
return render( |
|
request, |
|
"posts/post.html", |
|
{ |
|
"post": post, |
|
"comments": comments, |
|
"comments_count": comments_count, |
|
"nickname": nickname, |
|
}, |
|
)
|
|
|