thread.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. from django.core.urlresolvers import reverse
  2. from django.utils.translation import ugettext_lazy as _
  3. from . import ThreadType
  4. class Thread(ThreadType):
  5. root_name = 'root_category'
  6. def get_category_name(self, category):
  7. if category.level:
  8. return category.name
  9. else:
  10. return _('None (will become top level category)')
  11. def get_category_absolute_url(self, category):
  12. if category.level:
  13. return reverse('misago:category', kwargs={
  14. 'pk': category.pk,
  15. 'slug': category.slug,
  16. })
  17. else:
  18. return reverse('misago:threads')
  19. def get_category_last_thread_url(self, category):
  20. return reverse('misago:thread', kwargs={
  21. 'slug': category.last_thread.slug,
  22. 'pk': category.last_thread.pk
  23. })
  24. def get_category_last_post_url(self, category):
  25. return '/threads/%s-%s/last/' % (
  26. category.last_thread_slug,
  27. category.last_thread_id
  28. )
  29. def get_category_api_read_url(self, category):
  30. if category.level:
  31. return '%s?category=%s' % (reverse('misago:api:thread-read'), category.pk)
  32. else:
  33. return reverse('misago:api:thread-read')
  34. def get_thread_absolute_url(self, thread, page=1):
  35. if page > 1:
  36. return reverse('misago:thread', kwargs={
  37. 'slug': thread.slug,
  38. 'pk': thread.pk,
  39. 'page': page
  40. })
  41. else:
  42. return reverse('misago:thread', kwargs={
  43. 'slug': thread.slug,
  44. 'pk': thread.pk
  45. })
  46. def get_thread_last_post_url(self, thread):
  47. return reverse('misago:thread-last', kwargs={
  48. 'slug': thread.slug,
  49. 'pk': thread.pk
  50. })
  51. def get_thread_new_post_url(self, thread):
  52. return reverse('misago:thread-new', kwargs={
  53. 'slug': thread.slug,
  54. 'pk': thread.pk
  55. })
  56. def get_thread_unapproved_post_url(self, thread):
  57. return reverse('misago:thread-unapproved', kwargs={
  58. 'slug': thread.slug,
  59. 'pk': thread.pk
  60. })
  61. def get_thread_api_url(self, thread):
  62. return reverse('misago:api:thread-detail', kwargs={'pk': thread.pk})
  63. def get_post_absolute_url(self, post):
  64. return reverse('misago:thread-post', kwargs={
  65. 'slug': post.thread.slug,
  66. 'pk': post.thread.pk,
  67. 'post': post.pk
  68. })