thread.py 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. from django.utils.translation import ugettext as _
  2. from misago.apps.threadtype.thread import ThreadBaseView, ThreadModeration, PostsModeration
  3. from misago.models import Forum, Thread
  4. from misago.apps.threads.forms import PollVoteForm
  5. from misago.apps.threads.mixins import TypeMixin
  6. class ThreadView(ThreadBaseView, ThreadModeration, PostsModeration, TypeMixin):
  7. def template_vars(self, context):
  8. context['poll'] = None
  9. context['poll_form'] = None
  10. if self.thread.has_poll:
  11. context['poll'] = self.thread.poll
  12. self.thread.poll.message = self.request.messages.get_message('poll_%s' % self.thread.poll.pk)
  13. if self.request.user.is_authenticated():
  14. self.thread.poll.user_votes = [x.option_id for x in self.request.user.pollvote_set.filter(poll=self.thread.poll)]
  15. if self.request.acl.threads.can_vote_in_polls(self.forum, self.thread, self.thread.poll):
  16. context['poll_form'] = PollVoteForm(poll=self.thread.poll)
  17. return super(ThreadView, self).template_vars(context)
  18. def posts_actions(self):
  19. acl = self.request.acl.threads.get_role(self.thread.forum_id)
  20. actions = []
  21. try:
  22. if acl['can_approve'] and self.thread.replies_moderated > 0:
  23. actions.append(('accept', _('Accept posts')))
  24. if acl['can_move_threads_posts']:
  25. actions.append(('merge', _('Merge posts into one')))
  26. actions.append(('split', _('Split posts to new thread')))
  27. actions.append(('move', _('Move posts to other thread')))
  28. if acl['can_protect_posts']:
  29. actions.append(('protect', _('Protect posts')))
  30. actions.append(('unprotect', _('Remove posts protection')))
  31. if acl['can_delete_posts']:
  32. if self.thread.replies_deleted > 0:
  33. actions.append(('undelete', _('Restore posts')))
  34. actions.append(('soft', _('Hide posts')))
  35. if acl['can_delete_posts'] == 2:
  36. actions.append(('hard', _('Delete posts')))
  37. except KeyError:
  38. pass
  39. return actions
  40. def thread_actions(self):
  41. acl = self.request.acl.threads.get_role(self.thread.forum_id)
  42. actions = []
  43. try:
  44. if acl['can_approve'] and self.thread.moderated:
  45. actions.append(('accept', _('Accept this thread')))
  46. if acl['can_pin_threads'] == 2 and self.thread.weight < 2:
  47. actions.append(('annouce', _('Change this thread to announcement')))
  48. if acl['can_pin_threads'] > 0 and self.thread.weight != 1:
  49. actions.append(('sticky', _('Change this thread to sticky')))
  50. if acl['can_pin_threads'] > 0:
  51. if self.thread.weight == 2:
  52. actions.append(('normal', _('Change this thread to normal')))
  53. if self.thread.weight == 1:
  54. actions.append(('normal', _('Unpin this thread')))
  55. if acl['can_move_threads_posts']:
  56. actions.append(('move', _('Move this thread')))
  57. if acl['can_close_threads']:
  58. if self.thread.closed:
  59. actions.append(('open', _('Open this thread')))
  60. else:
  61. actions.append(('close', _('Close this thread')))
  62. if acl['can_delete_threads']:
  63. if self.thread.deleted:
  64. actions.append(('undelete', _('Restore this thread')))
  65. else:
  66. actions.append(('soft', _('Hide this thread')))
  67. if acl['can_delete_threads'] == 2:
  68. actions.append(('hard', _('Delete this thread')))
  69. except KeyError:
  70. pass
  71. return actions