patch.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. from misago.core.apipatchrouter import ApiPatchRouter
  2. from misago.threads.moderation import threads as moderation
  3. thread_patch_endpoint = ApiPatchRouter()
  4. def patch_weight(request, thread, value):
  5. if value == 2:
  6. moderation.pin_thread_globally(request.user, thread)
  7. if value == 1:
  8. moderation.pin_thread_locally(request.user, thread)
  9. if value == 0:
  10. moderation.unpin_thread(request.user, thread)
  11. return {'weight': thread.weight}
  12. thread_patch_endpoint.replace('weight', patch_weight)
  13. def patch_subscribtion(request, thread, value):
  14. request.user.subscription_set.filter(thread=thread).delete()
  15. if value == 'notify':
  16. thread.subscription = request.user.subscription_set.create(
  17. thread=thread,
  18. category=thread.category,
  19. last_read_on=thread.last_post_on,
  20. send_email=False,
  21. )
  22. return {'subscription': False}
  23. elif value == 'email':
  24. thread.subscription = request.user.subscription_set.create(
  25. thread=thread,
  26. category=thread.category,
  27. last_read_on=thread.last_post_on,
  28. send_email=True,
  29. )
  30. return {'subscription': True}
  31. else:
  32. return {'subscription': None}
  33. thread_patch_endpoint.replace('subscription', patch_subscribtion)