10
10
from django.urls import reverse
11
11
from django.db import connection
12
12
from django.utils import translation
13
from django.shortcuts import render
13
from django.shortcuts import render, redirect
16
16
from pybb.util import render_to, paged, build_form, quote_text, ajax, urlize
31
31
def index_ctx(request):
32
quick = {'posts': Post.objects.count(),
33
'topics': Topic.objects.count(),
34
'users': User.objects.count(),
35
'last_topics': Topic.objects.all().select_related()[:pybb_settings.QUICK_TOPICS_NUMBER],
36
'last_posts': Post.objects.order_by('-created').select_related()[:pybb_settings.QUICK_POSTS_NUMBER],
39
32
cats = Category.objects.all().select_related()
34
return {'cats': cats }
44
35
index = render_to('pybb/index.html')(index_ctx)
47
38
def show_category_ctx(request, category_id):
48
39
category = get_object_or_404(Category, pk=category_id)
49
quick = {'posts': category.posts.count(),
50
'topics': category.topics.count(),
51
'last_topics': category.topics.select_related()[:pybb_settings.QUICK_TOPICS_NUMBER],
52
'last_posts': category.posts.order_by('-created').select_related()
53
[:pybb_settings.QUICK_POSTS_NUMBER],
55
return {'category': category,
41
return {'category': category }
58
42
show_category = render_to('pybb/category.html')(show_category_ctx)
61
45
def show_forum_ctx(request, forum_id):
62
46
forum = get_object_or_404(Forum, pk=forum_id)
64
quick = {'posts': forum.post_count,
65
'topics': forum.topics.count(),
66
'last_topics': forum.topics.all().select_related()[:pybb_settings.QUICK_TOPICS_NUMBER],
67
'last_posts': forum.posts.order_by('-created').select_related()
68
[:pybb_settings.QUICK_POSTS_NUMBER],
48
moderator = (request.user.is_superuser or
49
request.user in forum.moderators.all())
71
51
topics = forum.topics.order_by(
72
'-sticky', '-updated').exclude(posts__hidden=True).select_related()
52
'-sticky', '-updated').select_related()
74
54
return {'forum': forum,
77
56
'page_size': pybb_settings.FORUM_PAGE_SIZE,
57
'moderator': moderator,
79
59
show_forum = render_to('pybb/forum.html')(show_forum_ctx)
106
86
subscribed = (request.user.is_authenticated and
107
87
request.user in topic.subscribers.all())
109
posts = topic.posts.exclude(hidden=True).select_related()
92
is_spam = topic.posts.first().is_spam()
95
posts = topic.posts.select_related()
97
posts = topic.posts.exclude(hidden=True).select_related()
111
99
# TODO: fetch profiles
112
100
# profiles = Profile.objects.filter(user__pk__in=
113
101
# set(x.user.id for x in page.object_list))
394
383
def pybb_moderate_info(request):
395
384
return render(request, 'pybb/pybb_moderate_info.html')
387
def toggle_hidden_topic(request, topic_id):
388
topic = get_object_or_404(Topic, pk=topic_id)
389
first_post = topic.posts.all()[0]
390
if first_post.hidden:
391
first_post.hidden = False
393
first_post.hidden = True
396
return redirect(topic)
b'\\ No newline at end of file'