thread.py 4.0 KB

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