thread.py 3.8 KB

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