threads.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. def announce_thread(user, thread):
  2. if thread.weight < 2:
  3. thread.weight = 2
  4. thread.save(update_fields=['weight'])
  5. return True
  6. else:
  7. return False
  8. def pin_thread(user, thread):
  9. if thread.weight < 1:
  10. thread.weight = 1
  11. thread.save(update_fields=['weight'])
  12. return True
  13. else:
  14. return False
  15. def default_thread(user, thread):
  16. if thread.weight > 0:
  17. thread.weight = 0
  18. thread.save(update_fields=['weight'])
  19. return True
  20. else:
  21. return False
  22. def move_thread(user, thread, new_forum):
  23. if thread.forum_id != new_forum.pk:
  24. thread.move(new_forum)
  25. thread.save(update_fields=['forum'])
  26. return True
  27. else:
  28. return False
  29. def merge_thread(user, thread, other_thread):
  30. thread.merge(other_thread)
  31. thread.synchornize()
  32. thread.save()
  33. other_thread.delete()
  34. return True
  35. def approve_thread(user, thread):
  36. if thread.is_moderated:
  37. thread.is_closed = False
  38. thread.first_post.is_moderated = False
  39. thread.first_post.save(update_fields=['is_moderated'])
  40. thread.synchornize()
  41. thread.save()
  42. return True
  43. else:
  44. return False
  45. def open_thread(user, thread):
  46. if thread.is_closed:
  47. thread.is_closed = False
  48. thread.save(update_fields=['is_closed'])
  49. return True
  50. else:
  51. return False
  52. def close_thread(user, thread):
  53. if not thread.is_closed:
  54. thread.is_closed = True
  55. thread.save(update_fields=['is_closed'])
  56. return True
  57. else:
  58. return False
  59. def show_thread(user, thread):
  60. if thread.is_hidden:
  61. thread.first_post.is_hidden = False
  62. thread.first_post.save(update_fields=['is_hidden'])
  63. thread.is_hidden = False
  64. thread.save(update_fields=['is_hidden'])
  65. thread.synchornize()
  66. thread.save()
  67. return True
  68. else:
  69. return False
  70. def hide_thread(user, thread):
  71. if not thread.is_hidden:
  72. thread.is_hidden = True
  73. thread.save(update_fields=['is_hidden'])
  74. return True
  75. else:
  76. return False
  77. def delete_thread(user, thread):
  78. thread.delete()
  79. return True