def viewtopic request topic_id Отображает список постов темы ThisTopic

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
def viewtopic(request, topic_id):
""" Отображает список постов темы """
ThisTopic = Topic.objects.get(id = topic_id)
ThisTopic.posts = Post.objects.filter(topic = ThisTopic).order_by('order').order_by('date')
paginator = Paginator(ThisTopic.posts, 30) # !!!
try:
pagenumber = int(request.GET.get('page', '1'))
except ValueError:
pagenumber = 1
try:
postspage = paginator.page(pagenumber)
except (EmptyPage, InvalidPage):
postspage = paginator.page(paginator.num_pages)
for post in postspage.object_list:
if post.author.username != "bot":
#strip bbcode_uid
regex = "\[*(?:\:[a-z0-9]+)\]"
post.text = re.sub(regex, "]", post.text)
regex = "\[*(?:\:[a-z0-9]+)\="
post.text = re.sub(regex, "=", post.text)
#bbdecode
#post.text = render_bbcode(post.text, post.bbcode_uid)
post.text = rewrite_urls(post.text);
post.text = bbcode_render(post.text);
post.text = post.text.replace('&', '&')
post.title = post.title.replace('&', '&')
post.author.signature = bbcode_render(post.author.signature)
# poll
voters_count = 0
try:
poll = Poll.objects.get(topic = ThisTopic)
poll.variants = PollVariant.objects.filter(poll = poll).all()
for variant in poll.variants:
voters_count += variant.votes
for variant in poll.variants:
variant.weight = int(round(1.0 * int(variant.votes) / voters_count * 100))
#except:
# # нету ещё вариантов
# ThisTopic.poll.variants = None
except:
#нету тут голосования.
poll = None
ThisTopic.voters_count = voters_count
ThisTopic.poll = poll
request.user = OTuser.objects.get(id = request.user.id)
t = loader.get_template('forum/viewtopic.html')
c = Context({
'MEDIA_URL': settings.MEDIA_URL,
'ThisTopic': ThisTopic,
'posts': postspage.object_list,
'postspage': postspage,
'paginator': paginator,
'request' : request,
})
return HttpResponse(t.render(c))