threads.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. from django.utils import timezone
  2. from ..threads.models import Thread
  3. from .englishcorpus import EnglishCorpus
  4. from .posts import get_fake_hidden_post, get_fake_post, get_fake_unapproved_post
  5. corpus_short = EnglishCorpus(max_length=150)
  6. def get_fake_thread(fake, category, starter):
  7. thread = create_fake_thread(fake, category, starter)
  8. thread.first_post = get_fake_post(fake, thread, starter)
  9. thread.save(update_fields=["first_post"])
  10. return thread
  11. def get_fake_closed_thread(fake, category, starter):
  12. thread = get_fake_thread(fake, category, starter)
  13. thread.is_closed = True
  14. thread.save(update_fields=["is_closed"])
  15. return thread
  16. def get_fake_hidden_thread(fake, category, starter, hidden_by=None):
  17. thread = create_fake_thread(fake, category, starter)
  18. thread.first_post = get_fake_hidden_post(fake, thread, starter, hidden_by)
  19. thread.save(update_fields=["first_post"])
  20. return thread
  21. def get_fake_unapproved_thread(fake, category, starter):
  22. thread = create_fake_thread(fake, category, starter)
  23. thread.first_post = get_fake_unapproved_post(fake, thread, starter)
  24. thread.save(update_fields=["first_post"])
  25. return thread
  26. def create_fake_thread(fake, category, starter):
  27. started_on = timezone.now()
  28. thread = Thread(
  29. category=category,
  30. started_on=started_on,
  31. starter_name="-",
  32. starter_slug="-",
  33. last_post_on=started_on,
  34. last_poster_name="-",
  35. last_poster_slug="-",
  36. replies=0,
  37. )
  38. thread.set_title(corpus_short.random_sentence())
  39. thread.save()
  40. return thread