thread.py 3.1 KB

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