thread.py 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. from django.utils.translation import ugettext as _
  2. from misago import messages
  3. from misago.apps.threadtype.thread import ThreadBaseView, ThreadModeration, PostsModeration
  4. from misago.messages import Message
  5. from misago.models import Forum, Thread
  6. from misago.monitor import monitor, UpdatingMonitor
  7. from misago.apps.reports.mixins import TypeMixin
  8. class ThreadView(ThreadBaseView, ThreadModeration, PostsModeration, TypeMixin):
  9. def fetch_thread(self):
  10. super(ThreadView, self).fetch_thread()
  11. self.thread.original_weight = self.thread.weight
  12. def posts_actions(self):
  13. acl = self.request.acl.threads.get_role(self.thread.forum_id)
  14. actions = []
  15. try:
  16. if acl['can_delete_posts']:
  17. if self.thread.replies_deleted > 0:
  18. actions.append(('undelete', _('Restore posts')))
  19. actions.append(('soft', _('Hide posts')))
  20. if acl['can_delete_posts'] == 2:
  21. actions.append(('hard', _('Delete posts')))
  22. except KeyError:
  23. pass
  24. return actions
  25. def thread_actions(self):
  26. acl = self.request.acl.threads.get_role(self.thread.forum_id)
  27. actions = []
  28. try:
  29. if self.thread.weight != 1:
  30. actions.append(('sticky', _('Change to resolved')))
  31. if self.thread.weight != 0:
  32. actions.append(('normal', _('Change to bogus')))
  33. if acl['can_delete_threads']:
  34. if self.thread.deleted:
  35. actions.append(('undelete', _('Restore this report')))
  36. else:
  37. actions.append(('soft', _('Hide this report')))
  38. if acl['can_delete_threads'] == 2:
  39. actions.append(('hard', _('Delete this report')))
  40. except KeyError:
  41. pass
  42. return actions
  43. def after_thread_action_sticky(self):
  44. self.thread.set_checkpoint(self.request, 'resolved')
  45. if self.thread.original_weight == 2:
  46. with UpdatingMonitor() as cm:
  47. monitor.decrease('reported_posts')
  48. messages.success(self.request, _('Report has been set as resolved.'), 'threads')
  49. def after_thread_action_normal(self):
  50. self.thread.set_checkpoint(self.request, 'bogus')
  51. if self.thread.original_weight == 2:
  52. with UpdatingMonitor() as cm:
  53. monitor.decrease('reported_posts')
  54. messages.success(self.request, _('Report has been set as bogus.'), 'threads')
  55. def after_thread_action_undelete(self):
  56. if self.thread.original_weight == 2:
  57. with UpdatingMonitor() as cm:
  58. monitor.increase('reported_posts')
  59. messages.success(self.request, _('Report has been restored.'), 'threads')
  60. def after_thread_action_soft(self):
  61. if self.thread.original_weight == 2:
  62. with UpdatingMonitor() as cm:
  63. monitor.decrease('reported_posts')
  64. messages.success(self.request, _('Report has been hidden.'), 'threads')
  65. def after_thread_action_hard(self):
  66. messages.success(self.request, _('Report "%(thread)s" has been deleted.') % {'thread': self.thread.name}, 'threads')