thread.py 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  1. from django.core.urlresolvers import reverse
  2. from django import forms
  3. from django.db.models import F
  4. from django.forms import ValidationError
  5. from django.shortcuts import redirect
  6. from django.template import RequestContext
  7. from django.utils import timezone
  8. from django.utils.translation import ugettext as _
  9. from misago.acl.utils import ACLError403, ACLError404
  10. from misago.forms import Form, FormLayout, FormFields
  11. from misago.forums.models import Forum
  12. from misago.markdown import post_markdown
  13. from misago.messages import Message
  14. from misago.readstracker.trackers import ThreadsTracker
  15. from misago.threads.forms import MoveThreadsForm, SplitThreadForm, MovePostsForm, QuickReplyForm
  16. from misago.threads.models import Thread, Post, Change, Checkpoint
  17. from misago.threads.views.base import BaseView
  18. from misago.views import error403, error404
  19. from misago.utils import make_pagination, slugify
  20. class ThreadView(BaseView):
  21. def fetch_thread(self, thread):
  22. self.thread = Thread.objects.get(pk=thread)
  23. self.forum = self.thread.forum
  24. self.proxy = Forum.objects.parents_aware_forum(self.forum)
  25. self.request.acl.forums.allow_forum_view(self.forum)
  26. self.request.acl.threads.allow_thread_view(self.request.user, self.thread)
  27. self.parents = Forum.objects.forum_parents(self.forum.pk, True)
  28. self.tracker = ThreadsTracker(self.request, self.forum)
  29. def fetch_posts(self, page):
  30. self.count = self.request.acl.threads.filter_posts(self.request, self.thread, Post.objects.filter(thread=self.thread)).count()
  31. self.posts = self.request.acl.threads.filter_posts(self.request, self.thread, Post.objects.filter(thread=self.thread)).prefetch_related('checkpoint_set', 'user', 'user__rank')
  32. if self.thread.merges > 0:
  33. self.posts = self.posts.order_by('merge', 'pk')
  34. else:
  35. self.posts = self.posts.order_by('pk')
  36. self.pagination = make_pagination(page, self.count, self.request.settings.posts_per_page)
  37. if self.request.settings.posts_per_page < self.count:
  38. self.posts = self.posts[self.pagination['start']:self.pagination['stop']]
  39. self.read_date = self.tracker.get_read_date(self.thread)
  40. ignored_users = []
  41. if self.request.user.is_authenticated():
  42. ignored_users = self.request.user.ignored_users()
  43. for post in self.posts:
  44. post.message = self.request.messages.get_message('threads_%s' % post.pk)
  45. post.is_read = post.date <= self.read_date
  46. post.ignored = self.thread.start_post_id != post.pk and not self.thread.pk in self.request.session.get('unignore_threads', []) and post.user_id in ignored_users
  47. if post.ignored:
  48. self.ignored = True
  49. last_post = self.posts[len(self.posts) - 1]
  50. if not self.tracker.is_read(self.thread):
  51. self.tracker.set_read(self.thread, last_post)
  52. self.tracker.sync()
  53. def get_post_actions(self):
  54. acl = self.request.acl.threads.get_role(self.thread.forum_id)
  55. actions = []
  56. try:
  57. if acl['can_approve'] and self.thread.replies_moderated > 0:
  58. actions.append(('accept', _('Accept posts')))
  59. if acl['can_move_threads_posts']:
  60. actions.append(('merge', _('Merge posts into one')))
  61. actions.append(('split', _('Split posts to new thread')))
  62. actions.append(('move', _('Move posts to other thread')))
  63. if acl['can_protect_posts']:
  64. actions.append(('protect', _('Protect posts')))
  65. actions.append(('unprotect', _('Remove posts protection')))
  66. if acl['can_delete_posts']:
  67. if self.thread.replies_deleted > 0:
  68. actions.append(('undelete', _('Undelete posts')))
  69. actions.append(('soft', _('Soft delete posts')))
  70. if acl['can_delete_posts'] == 2:
  71. actions.append(('hard', _('Hard delete posts')))
  72. except KeyError:
  73. pass
  74. return actions
  75. def make_posts_form(self):
  76. self.posts_form = None
  77. list_choices = self.get_post_actions();
  78. if (not self.request.user.is_authenticated()
  79. or not list_choices):
  80. return
  81. form_fields = {}
  82. form_fields['list_action'] = forms.ChoiceField(choices=list_choices)
  83. list_choices = []
  84. for item in self.posts:
  85. list_choices.append((item.pk, None))
  86. if not list_choices:
  87. return
  88. form_fields['list_items'] = forms.MultipleChoiceField(choices=list_choices, widget=forms.CheckboxSelectMultiple)
  89. self.posts_form = type('PostsViewForm', (Form,), form_fields)
  90. def handle_posts_form(self):
  91. if self.request.method == 'POST' and self.request.POST.get('origin') == 'posts_form':
  92. self.posts_form = self.posts_form(self.request.POST, request=self.request)
  93. if self.posts_form.is_valid():
  94. checked_items = []
  95. for post in self.posts:
  96. if str(post.pk) in self.posts_form.cleaned_data['list_items']:
  97. checked_items.append(post.pk)
  98. if checked_items:
  99. form_action = getattr(self, 'post_action_' + self.posts_form.cleaned_data['list_action'])
  100. try:
  101. response = form_action(checked_items)
  102. if response:
  103. return response
  104. return redirect(self.request.path)
  105. except forms.ValidationError as e:
  106. self.message = Message(e.messages[0], 'error')
  107. else:
  108. self.message = Message(_("You have to select at least one post."), 'error')
  109. else:
  110. if 'list_action' in self.posts_form.errors:
  111. self.message = Message(_("Action requested is incorrect."), 'error')
  112. else:
  113. self.message = Message(posts_form.non_field_errors()[0], 'error')
  114. else:
  115. self.posts_form = self.posts_form(request=self.request)
  116. def post_action_accept(self, ids):
  117. accepted = 0
  118. for post in self.posts:
  119. if post.pk in ids and post.moderated:
  120. accepted += 1
  121. if accepted:
  122. self.thread.post_set.filter(id__in=ids).update(moderated=False)
  123. self.thread.sync()
  124. self.thread.save(force_update=True)
  125. self.request.messages.set_flash(Message(_('Selected posts have been accepted and made visible to other members.')), 'success', 'threads')
  126. def post_action_merge(self, ids):
  127. users = []
  128. posts = []
  129. for post in self.posts:
  130. if post.pk in ids:
  131. posts.append(post)
  132. if not post.user_id in users:
  133. users.append(post.user_id)
  134. if len(users) > 1:
  135. raise forms.ValidationError(_("You cannot merge replies made by different members!"))
  136. if len(posts) < 2:
  137. raise forms.ValidationError(_("You have to select two or more posts you want to merge."))
  138. new_post = posts[0]
  139. for post in posts[1:]:
  140. post.merge_with(new_post)
  141. post.delete()
  142. new_post.post_preparsed = post_markdown(self.request, new_post.post)
  143. new_post.save(force_update=True)
  144. self.thread.sync()
  145. self.thread.save(force_update=True)
  146. self.forum.sync()
  147. self.forum.save(force_update=True)
  148. self.request.messages.set_flash(Message(_('Selected posts have been merged into one message.')), 'success', 'threads')
  149. def post_action_split(self, ids):
  150. for id in ids:
  151. if id == self.thread.start_post_id:
  152. raise forms.ValidationError(_("You cannot split first post from thread."))
  153. message = None
  154. if self.request.POST.get('do') == 'split':
  155. form = SplitThreadForm(self.request.POST, request=self.request)
  156. if form.is_valid():
  157. new_thread = Thread()
  158. new_thread.forum = form.cleaned_data['thread_forum']
  159. new_thread.name = form.cleaned_data['thread_name']
  160. new_thread.slug = slugify(form.cleaned_data['thread_name'])
  161. new_thread.start = timezone.now()
  162. new_thread.last = timezone.now()
  163. new_thread.start_poster_name = 'n'
  164. new_thread.start_poster_slug = 'n'
  165. new_thread.last_poster_name = 'n'
  166. new_thread.last_poster_slug = 'n'
  167. new_thread.save(force_insert=True)
  168. prev_merge = -1
  169. merge = -1
  170. for post in self.posts:
  171. if post.pk in ids:
  172. if prev_merge != post.merge:
  173. prev_merge = post.merge
  174. merge += 1
  175. post.merge = merge
  176. post.move_to(new_thread)
  177. post.save(force_update=True)
  178. new_thread.sync()
  179. new_thread.save(force_update=True)
  180. self.thread.sync()
  181. self.thread.save(force_update=True)
  182. self.forum.sync()
  183. self.forum.save(force_update=True)
  184. if new_thread.forum != self.forum:
  185. new_thread.forum.sync()
  186. new_thread.forum.save(force_update=True)
  187. self.request.messages.set_flash(Message(_("Selected posts have been split to new thread.")), 'success', 'threads')
  188. return redirect(reverse('thread', kwargs={'thread': new_thread.pk, 'slug': new_thread.slug}))
  189. message = Message(form.non_field_errors()[0], 'error')
  190. else:
  191. form = SplitThreadForm(request=self.request, initial={
  192. 'thread_name': _('[Split] %s') % self.thread.name,
  193. 'thread_forum': self.forum,
  194. })
  195. return self.request.theme.render_to_response('threads/split.html',
  196. {
  197. 'message': message,
  198. 'forum': self.forum,
  199. 'parents': self.parents,
  200. 'thread': self.thread,
  201. 'posts': ids,
  202. 'form': FormLayout(form),
  203. },
  204. context_instance=RequestContext(self.request));
  205. def post_action_move(self, ids):
  206. message = None
  207. if self.request.POST.get('do') == 'move':
  208. form = MovePostsForm(self.request.POST, request=self.request, thread=self.thread)
  209. if form.is_valid():
  210. thread = form.cleaned_data['thread_url']
  211. prev_merge = -1
  212. merge = -1
  213. for post in self.posts:
  214. if post.pk in ids:
  215. if prev_merge != post.merge:
  216. prev_merge = post.merge
  217. merge += 1
  218. post.merge = merge + thread.merges
  219. post.move_to(thread)
  220. post.save(force_update=True)
  221. if self.thread.post_set.count() == 0:
  222. self.thread.delete()
  223. else:
  224. self.thread.sync()
  225. self.thread.save(force_update=True)
  226. thread.sync()
  227. thread.save(force_update=True)
  228. thread.forum.sync()
  229. thread.forum.save(force_update=True)
  230. if self.forum.pk != thread.forum.pk:
  231. self.forum.sync()
  232. self.forum.save(force_update=True)
  233. self.request.messages.set_flash(Message(_("Selected posts have been moved to new thread.")), 'success', 'threads')
  234. return redirect(reverse('thread', kwargs={'thread': thread.pk, 'slug': thread.slug}))
  235. message = Message(form.non_field_errors()[0], 'error')
  236. else:
  237. form = MovePostsForm(request=self.request)
  238. return self.request.theme.render_to_response('threads/move.html',
  239. {
  240. 'message': message,
  241. 'forum': self.forum,
  242. 'parents': self.parents,
  243. 'thread': self.thread,
  244. 'posts': ids,
  245. 'form': FormLayout(form),
  246. },
  247. context_instance=RequestContext(self.request));
  248. def post_action_undelete(self, ids):
  249. undeleted = []
  250. for post in self.posts:
  251. if post.pk in ids and post.deleted:
  252. undeleted.append(post.pk)
  253. if undeleted:
  254. self.thread.post_set.filter(id__in=undeleted).update(deleted=False)
  255. self.thread.sync()
  256. self.thread.save(force_update=True)
  257. self.forum.sync()
  258. self.forum.save(force_update=True)
  259. self.request.messages.set_flash(Message(_('Selected posts have been restored.')), 'success', 'threads')
  260. def post_action_protect(self, ids):
  261. protected = 0
  262. for post in self.posts:
  263. if post.pk in ids and not post.protected:
  264. protected += 1
  265. if protected:
  266. self.thread.post_set.filter(id__in=ids).update(protected=True)
  267. self.request.messages.set_flash(Message(_('Selected posts have been protected from edition.')), 'success', 'threads')
  268. def post_action_unprotect(self, ids):
  269. unprotected = 0
  270. for post in self.posts:
  271. if post.pk in ids and post.protected:
  272. unprotected += 1
  273. if unprotected:
  274. self.thread.post_set.filter(id__in=ids).update(protected=False)
  275. self.request.messages.set_flash(Message(_('Protection from editions has been removed from selected posts.')), 'success', 'threads')
  276. def post_action_soft(self, ids):
  277. deleted = []
  278. for post in self.posts:
  279. if post.pk in ids and not post.deleted:
  280. if post.pk == self.thread.start_post_id:
  281. raise forms.ValidationError(_("You cannot delete first post of thread using this action. If you want to delete thread, use thread moderation instead."))
  282. deleted.append(post.pk)
  283. if deleted:
  284. self.thread.post_set.filter(id__in=deleted).update(deleted=True)
  285. self.thread.sync()
  286. self.thread.save(force_update=True)
  287. self.forum.sync()
  288. self.forum.save(force_update=True)
  289. self.request.messages.set_flash(Message(_('Selected posts have been deleted.')), 'success', 'threads')
  290. def post_action_hard(self, ids):
  291. deleted = []
  292. for post in self.posts:
  293. if post.pk in ids and not post.deleted:
  294. if post.pk == self.thread.start_post_id:
  295. raise forms.ValidationError(_("You cannot delete first post of thread using this action. If you want to delete thread, use thread moderation instead."))
  296. deleted.append(post.pk)
  297. if deleted:
  298. for post in deleted:
  299. post.delete()
  300. self.thread.post_set.filter(id__in=deleted).delete()
  301. Change.objects.d(post__in=ids).delete()
  302. Checkpoint.objects.filter(post__in=ids).delete()
  303. self.thread.sync()
  304. self.thread.save(force_update=True)
  305. self.forum.sync()
  306. self.forum.save(force_update=True)
  307. self.request.messages.set_flash(Message(_('Selected posts have been deleted.')), 'success', 'threads')
  308. def get_thread_actions(self):
  309. acl = self.request.acl.threads.get_role(self.thread.forum_id)
  310. actions = []
  311. try:
  312. if acl['can_approve'] and self.thread.moderated:
  313. actions.append(('accept', _('Accept this thread')))
  314. if acl['can_pin_threads'] == 2 and self.thread.weight < 2:
  315. actions.append(('annouce', _('Change this thread to annoucement')))
  316. if acl['can_pin_threads'] > 0 and self.thread.weight != 1:
  317. actions.append(('sticky', _('Change this thread to sticky')))
  318. if acl['can_pin_threads'] > 0:
  319. if self.thread.weight == 2:
  320. actions.append(('normal', _('Change this thread to normal')))
  321. if self.thread.weight == 1:
  322. actions.append(('normal', _('Unpin this thread')))
  323. if acl['can_move_threads_posts']:
  324. actions.append(('move', _('Move this thread')))
  325. if acl['can_close_threads']:
  326. if self.thread.closed:
  327. actions.append(('open', _('Open this thread')))
  328. else:
  329. actions.append(('close', _('Close this thread')))
  330. if acl['can_delete_threads']:
  331. if self.thread.deleted:
  332. actions.append(('undelete', _('Undelete this thread')))
  333. else:
  334. actions.append(('soft', _('Soft delete this thread')))
  335. if acl['can_delete_threads'] == 2:
  336. actions.append(('hard', _('Hard delete this thread')))
  337. except KeyError:
  338. pass
  339. return actions
  340. def make_thread_form(self):
  341. self.thread_form = None
  342. list_choices = self.get_thread_actions();
  343. if (not self.request.user.is_authenticated()
  344. or not list_choices):
  345. return
  346. form_fields = {'thread_action': forms.ChoiceField(choices=list_choices)}
  347. self.thread_form = type('ThreadViewForm', (Form,), form_fields)
  348. def handle_thread_form(self):
  349. if self.request.method == 'POST' and self.request.POST.get('origin') == 'thread_form':
  350. self.thread_form = self.thread_form(self.request.POST, request=self.request)
  351. if self.thread_form.is_valid():
  352. form_action = getattr(self, 'thread_action_' + self.thread_form.cleaned_data['thread_action'])
  353. try:
  354. response = form_action()
  355. if response:
  356. return response
  357. return redirect(self.request.path)
  358. except forms.ValidationError as e:
  359. self.message = Message(e.messages[0], 'error')
  360. else:
  361. if 'thread_action' in self.thread_form.errors:
  362. self.message = Message(_("Action requested is incorrect."), 'error')
  363. else:
  364. self.message = Message(form.non_field_errors()[0], 'error')
  365. else:
  366. self.thread_form = self.thread_form(request=self.request)
  367. def thread_action_accept(self):
  368. # Sync thread and post
  369. self.thread.moderated = False
  370. self.thread.replies_moderated -= 1
  371. self.thread.save(force_update=True)
  372. self.thread.start_post.moderated = False
  373. self.thread.start_post.save(force_update=True)
  374. self.thread.last_post.set_checkpoint(self.request, 'accepted')
  375. # Sync user
  376. if self.thread.last_post.user:
  377. self.thread.start_post.user.threads += 1
  378. self.thread.start_post.user.posts += 1
  379. self.thread.start_post.user.save(force_update=True)
  380. # Sync forum
  381. self.forum.threads_delta += 1
  382. self.forum.posts_delta += self.thread.replies + 1
  383. self.forum.sync()
  384. self.forum.save(force_update=True)
  385. # Update monitor
  386. self.request.monitor['threads'] = int(self.request.monitor['threads']) + 1
  387. self.request.monitor['posts'] = int(self.request.monitor['posts']) + self.thread.replies + 1
  388. self.request.messages.set_flash(Message(_('Thread has been marked as reviewed and made visible to other members.')), 'success', 'threads')
  389. def thread_action_annouce(self):
  390. self.thread.weight = 2
  391. self.thread.save(force_update=True)
  392. self.request.messages.set_flash(Message(_('Thread has been turned into annoucement.')), 'success', 'threads')
  393. def thread_action_sticky(self):
  394. self.thread.weight = 1
  395. self.thread.save(force_update=True)
  396. self.request.messages.set_flash(Message(_('Thread has been turned into sticky.')), 'success', 'threads')
  397. def thread_action_normal(self):
  398. self.thread.weight = 0
  399. self.thread.save(force_update=True)
  400. self.request.messages.set_flash(Message(_('Thread weight has been changed to normal.')), 'success', 'threads')
  401. def thread_action_move(self):
  402. message = None
  403. if self.request.POST.get('do') == 'move':
  404. form = MoveThreadsForm(self.request.POST, request=self.request, forum=self.forum)
  405. if form.is_valid():
  406. new_forum = form.cleaned_data['new_forum']
  407. self.thread.move_to(new_forum)
  408. self.thread.save(force_update=True)
  409. self.forum.sync()
  410. self.forum.save(force_update=True)
  411. new_forum.sync()
  412. new_forum.save(force_update=True)
  413. self.request.messages.set_flash(Message(_('Thread has been moved to "%(forum)s".') % {'forum': new_forum.name}), 'success', 'threads')
  414. return None
  415. message = Message(form.non_field_errors()[0], 'error')
  416. else:
  417. form = MoveThreadsForm(request=self.request, forum=self.forum)
  418. return self.request.theme.render_to_response('threads/move.html',
  419. {
  420. 'message': message,
  421. 'forum': self.forum,
  422. 'parents': self.parents,
  423. 'thread': self.thread,
  424. 'form': FormLayout(form),
  425. },
  426. context_instance=RequestContext(self.request));
  427. def thread_action_open(self):
  428. self.thread.closed = False
  429. self.thread.save(force_update=True)
  430. self.thread.last_post.set_checkpoint(self.request, 'opened')
  431. self.request.messages.set_flash(Message(_('Thread has been opened.')), 'success', 'threads')
  432. def thread_action_close(self):
  433. self.thread.closed = True
  434. self.thread.save(force_update=True)
  435. self.thread.last_post.set_checkpoint(self.request, 'closed')
  436. self.request.messages.set_flash(Message(_('Thread has been closed.')), 'success', 'threads')
  437. def thread_action_undelete(self):
  438. # Update thread
  439. self.thread.deleted = False
  440. self.thread.replies_deleted -= 1
  441. self.thread.save(force_update=True)
  442. # Update first post in thread
  443. self.thread.start_post.deleted = False
  444. self.thread.start_post.save(force_update=True)
  445. # Set checkpoint
  446. self.thread.last_post.set_checkpoint(self.request, 'undeleted')
  447. # Update forum
  448. self.forum.sync()
  449. self.forum.save(force_update=True)
  450. # Update monitor
  451. self.request.monitor['threads'] = int(self.request.monitor['threads']) + 1
  452. self.request.monitor['posts'] = int(self.request.monitor['posts']) + self.thread.replies + 1
  453. self.request.messages.set_flash(Message(_('Thread has been undeleted.')), 'success', 'threads')
  454. def thread_action_soft(self):
  455. # Update thread
  456. self.thread.deleted = True
  457. self.thread.replies_deleted += 1
  458. self.thread.save(force_update=True)
  459. # Update first post in thread
  460. self.thread.start_post.deleted = True
  461. self.thread.start_post.save(force_update=True)
  462. # Set checkpoint
  463. self.thread.last_post.set_checkpoint(self.request, 'deleted')
  464. # Update forum
  465. self.forum.sync()
  466. self.forum.save(force_update=True)
  467. # Update monitor
  468. self.request.monitor['threads'] = int(self.request.monitor['threads']) - 1
  469. self.request.monitor['posts'] = int(self.request.monitor['posts']) - self.thread.replies - 1
  470. self.request.messages.set_flash(Message(_('Thread has been deleted.')), 'success', 'threads')
  471. def thread_action_hard(self):
  472. # Delete thread
  473. self.thread.delete()
  474. # Update forum
  475. self.forum.sync()
  476. self.forum.save(force_update=True)
  477. # Update monitor
  478. self.request.monitor['threads'] = int(self.request.monitor['threads']) - 1
  479. self.request.monitor['posts'] = int(self.request.monitor['posts']) - self.thread.replies - 1
  480. self.request.messages.set_flash(Message(_('Thread "%(thread)s" has been deleted.') % {'thread': self.thread.name}), 'success', 'threads')
  481. return redirect(reverse('forum', kwargs={'forum': self.forum.pk, 'slug': self.forum.slug}))
  482. def __call__(self, request, slug=None, thread=None, page=0):
  483. self.request = request
  484. self.pagination = None
  485. self.parents = None
  486. self.ignored = False
  487. try:
  488. self.fetch_thread(thread)
  489. self.fetch_posts(page)
  490. self.message = request.messages.get_message('threads')
  491. self.make_thread_form()
  492. if self.thread_form:
  493. response = self.handle_thread_form()
  494. if response:
  495. return response
  496. self.make_posts_form()
  497. if self.posts_form:
  498. response = self.handle_posts_form()
  499. if response:
  500. return response
  501. except Thread.DoesNotExist:
  502. return error404(self.request)
  503. except ACLError403 as e:
  504. return error403(request, e.message)
  505. except ACLError404 as e:
  506. return error404(request, e.message)
  507. # Merge proxy into forum
  508. self.forum.closed = self.proxy.closed
  509. return request.theme.render_to_response('threads/thread.html',
  510. {
  511. 'message': self.message,
  512. 'forum': self.forum,
  513. 'parents': self.parents,
  514. 'thread': self.thread,
  515. 'is_read': self.tracker.is_read(self.thread),
  516. 'count': self.count,
  517. 'posts': self.posts,
  518. 'ignored_posts': self.ignored,
  519. 'pagination': self.pagination,
  520. 'quick_reply': FormFields(QuickReplyForm(request=request)).fields,
  521. 'thread_form': FormFields(self.thread_form).fields if self.thread_form else None,
  522. 'posts_form': FormFields(self.posts_form).fields if self.posts_form else None,
  523. },
  524. context_instance=RequestContext(request));