thread.py 3.9 KB

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