thread.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 '/threads/%s-%s/' % (
  21. category.last_thread_slug,
  22. category.last_thread_id,
  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 '/threads/not-implemented-yet-%s/last/' % thread.pk
  48. def get_thread_new_post_url(self, thread):
  49. return '/threads/not-implemented-yet-%s/new/' % thread.pk
  50. def get_thread_api_url(self, thread):
  51. return reverse('misago:api:thread-detail', kwargs={'pk': thread.pk})
  52. def get_post_absolute_url(self, post):
  53. return '/threads/not-implemented-yet-%s/post/' % post.pk