thread.py 28 KB

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