threads.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. from django.utils import timezone
  2. from ...englishcorpus import EnglishCorpus
  3. PLACEKITTEN_URL = "https://placekitten.com/g/%s/%s"
  4. corpus = EnglishCorpus()
  5. corpus_short = EnglishCorpus(max_length=150)
  6. def fake_thread(fake, category, starter):
  7. thread = Thread(
  8. category=category,
  9. started_on=timezone.now(),
  10. starter_name="-",
  11. starter_slug="-",
  12. last_post_on=timezone.now(),
  13. last_poster_name="-",
  14. last_poster_slug="-",
  15. replies=0,
  16. )
  17. thread.set_title(corpus_short.random_sentence())
  18. thread.save()
  19. return thread
  20. def fake_closed_thread(fake, category, starter):
  21. thread = fake_thread(fake, category, starter)
  22. thread.is_closed = True
  23. thread.save(update_fields=["is_closed"])
  24. return thread
  25. def fake_hidden_thread(fake, category, starter):
  26. thread = fake_thread(fake, category, starter)
  27. thread.is_hidden = True
  28. thread.save(update_fields=["is_hidden"])
  29. return thread
  30. def fake_unapproved_thread(fake, category, starter):
  31. thread = fake_thread(fake, category, starter)
  32. thread.is_hidden = True
  33. thread.save(update_fields=["is_hidden"])
  34. return thread