__init__.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. from django.conf import settings
  2. from django.conf.urls import url
  3. from misago.threads.views.lists import ThreadsList, CategoryThreadsList, PrivateThreadsList
  4. LISTS_TYPES = (
  5. 'all',
  6. 'my',
  7. 'new',
  8. 'unread',
  9. 'subscribed',
  10. 'unapproved',
  11. )
  12. def threads_list_patterns(root_name, view, patterns):
  13. listurls = []
  14. for i, pattern in enumerate(patterns):
  15. if i > 0:
  16. url_name = '%s-%s' % (root_name, LISTS_TYPES[i])
  17. else:
  18. url_name = root_name
  19. listurls.append(url(
  20. pattern,
  21. view.as_view(),
  22. name=url_name,
  23. kwargs={'list_type': LISTS_TYPES[i]},
  24. ))
  25. return listurls
  26. if settings.MISAGO_CATEGORIES_ON_INDEX:
  27. urlpatterns = threads_list_patterns('threads', ThreadsList, (
  28. r'^threads/$',
  29. r'^threads/my/$',
  30. r'^threads/new/$',
  31. r'^threads/unread/$',
  32. r'^threads/subscribed/$',
  33. r'^threads/unapproved/$',
  34. ))
  35. else:
  36. urlpatterns = threads_list_patterns('threads', ThreadsList, (
  37. r'^$',
  38. r'^my/$',
  39. r'^new/$',
  40. r'^unread/$',
  41. r'^subscribed/$',
  42. r'^unapproved/$',
  43. ))
  44. urlpatterns += threads_list_patterns('category', CategoryThreadsList, (
  45. r'^category/(?P<slug>[-a-zA-Z0-9]+)-(?P<pk>\d+)/$',
  46. r'^category/(?P<slug>[-a-zA-Z0-9]+)-(?P<pk>\d+)/my/$',
  47. r'^category/(?P<slug>[-a-zA-Z0-9]+)-(?P<pk>\d+)/new/$',
  48. r'^category/(?P<slug>[-a-zA-Z0-9]+)-(?P<pk>\d+)/unread/$',
  49. r'^category/(?P<slug>[-a-zA-Z0-9]+)-(?P<pk>\d+)/subscribed/$',
  50. r'^category/(?P<slug>[-a-zA-Z0-9]+)-(?P<pk>\d+)/unapproved/$',
  51. ))
  52. urlpatterns += threads_list_patterns('private-threads', CategoryThreadsList, (
  53. r'^private-threads/$',
  54. r'^private-threads/my/$',
  55. r'^private-threads/new/$',
  56. r'^private-threads/unread/$',
  57. r'^private-threads/subscribed/$',
  58. r'^private-threads/unapproved/$',
  59. ))