posts.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. from django.db.transaction import atomic
  2. from django.utils.translation import ugettext as _
  3. from misago.threads.moderation.exceptions import ModerationError
  4. @atomic
  5. def unhide_post(user, post):
  6. if post.pk == post.thread.first_post_id:
  7. raise ModerationError(_("You can't make original post "
  8. " visible without revealing thread."))
  9. if post.is_hidden:
  10. post.is_hidden = False
  11. post.save(update_fields=['is_hidden'])
  12. return True
  13. else:
  14. return False
  15. @atomic
  16. def hide_post(user, post):
  17. if post.pk == post.thread.first_post_id:
  18. raise ModerationError(_("You can't hide original "
  19. "post without hiding thread."))
  20. if not post.is_hidden:
  21. post.is_hidden = True
  22. post.save(update_fields=['is_hidden'])
  23. return True
  24. else:
  25. return False
  26. @atomic
  27. def delete_post(user, post):
  28. if post.pk == post.thread.first_post_id:
  29. raise ModerationError(_("You can't delete original "
  30. "post without deleting thread."))
  31. post.delete()
  32. return True