urls.py 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. from django.contrib.auth import views as auth_views
  2. from django.contrib.auth.decorators import login_required
  3. from django.urls import path, re_path
  4. from django.views.decorators.cache import cache_page
  5. from django.views.generic import TemplateView, dates
  6. from . import views
  7. from .models import Book
  8. urlpatterns = [
  9. # TemplateView
  10. path('template/no_template/', TemplateView.as_view()),
  11. path('template/login_required/', login_required(TemplateView.as_view())),
  12. path('template/simple/<foo>/', TemplateView.as_view(template_name='generic_views/about.html')),
  13. path(
  14. 'template/custom/<foo1>/<foo2>/',
  15. views.CustomTemplateView.as_view(template_name='generic_views/about.html'),
  16. ),
  17. path(
  18. 'template/content_type/',
  19. TemplateView.as_view(template_name='generic_views/robots.txt', content_type='text/plain'),
  20. ),
  21. path(
  22. 'template/cached/<foo>/',
  23. cache_page(2.0)(TemplateView.as_view(template_name='generic_views/about.html')),
  24. ),
  25. path(
  26. 'template/extra_context/',
  27. TemplateView.as_view(template_name='generic_views/about.html', extra_context={'title': 'Title'}),
  28. ),
  29. # DetailView
  30. path('detail/obj/', views.ObjectDetail.as_view()),
  31. path('detail/artist/<int:pk>/', views.ArtistDetail.as_view(), name='artist_detail'),
  32. path('detail/author/<int:pk>/', views.AuthorDetail.as_view(), name='author_detail'),
  33. path('detail/author/bycustompk/<foo>/', views.AuthorDetail.as_view(pk_url_kwarg='foo')),
  34. path('detail/author/byslug/<slug>/', views.AuthorDetail.as_view()),
  35. path('detail/author/bycustomslug/<foo>/', views.AuthorDetail.as_view(slug_url_kwarg='foo')),
  36. path('detail/author/bypkignoreslug/<int:pk>-<slug>/', views.AuthorDetail.as_view()),
  37. path('detail/author/bypkandslug/<int:pk>-<slug>/', views.AuthorDetail.as_view(query_pk_and_slug=True)),
  38. path('detail/author/<int:pk>/template_name_suffix/', views.AuthorDetail.as_view(template_name_suffix='_view')),
  39. path(
  40. 'detail/author/<int:pk>/template_name/',
  41. views.AuthorDetail.as_view(template_name='generic_views/about.html'),
  42. ),
  43. path('detail/author/<int:pk>/context_object_name/', views.AuthorDetail.as_view(context_object_name='thingy')),
  44. path('detail/author/<int:pk>/custom_detail/', views.AuthorCustomDetail.as_view()),
  45. path('detail/author/<int:pk>/dupe_context_object_name/', views.AuthorDetail.as_view(context_object_name='object')),
  46. path('detail/page/<int:pk>/field/', views.PageDetail.as_view()),
  47. path(r'detail/author/invalid/url/', views.AuthorDetail.as_view()),
  48. path('detail/author/invalid/qs/', views.AuthorDetail.as_view(queryset=None)),
  49. path('detail/nonmodel/1/', views.NonModelDetail.as_view()),
  50. path('detail/doesnotexist/<pk>/', views.ObjectDoesNotExistDetail.as_view()),
  51. # FormView
  52. path('contact/', views.ContactView.as_view()),
  53. path('late-validation/', views.LateValidationView.as_view()),
  54. # Create/UpdateView
  55. path('edit/artists/create/', views.ArtistCreate.as_view()),
  56. path('edit/artists/<int:pk>/update/', views.ArtistUpdate.as_view()),
  57. path('edit/authors/create/naive/', views.NaiveAuthorCreate.as_view()),
  58. path('edit/authors/create/redirect/', views.NaiveAuthorCreate.as_view(success_url='/edit/authors/create/')),
  59. path(
  60. 'edit/authors/create/interpolate_redirect/',
  61. views.NaiveAuthorCreate.as_view(success_url='/edit/author/{id}/update/'),
  62. ),
  63. path(
  64. 'edit/authors/create/interpolate_redirect_nonascii/',
  65. views.NaiveAuthorCreate.as_view(success_url='/%C3%A9dit/author/{id}/update/'),
  66. ),
  67. path('edit/authors/create/restricted/', views.AuthorCreateRestricted.as_view()),
  68. re_path('^[eé]dit/authors/create/$', views.AuthorCreate.as_view()),
  69. path('edit/authors/create/special/', views.SpecializedAuthorCreate.as_view()),
  70. path('edit/author/<int:pk>/update/naive/', views.NaiveAuthorUpdate.as_view()),
  71. path(
  72. 'edit/author/<int:pk>/update/redirect/',
  73. views.NaiveAuthorUpdate.as_view(success_url='/edit/authors/create/')
  74. ),
  75. path(
  76. 'edit/author/<int:pk>/update/interpolate_redirect/',
  77. views.NaiveAuthorUpdate.as_view(success_url='/edit/author/{id}/update/')
  78. ),
  79. path(
  80. 'edit/author/<int:pk>/update/interpolate_redirect_nonascii/',
  81. views.NaiveAuthorUpdate.as_view(success_url='/%C3%A9dit/author/{id}/update/'),
  82. ),
  83. re_path('^[eé]dit/author/(?P<pk>[0-9]+)/update/$', views.AuthorUpdate.as_view()),
  84. path('edit/author/update/', views.OneAuthorUpdate.as_view()),
  85. path('edit/author/<int:pk>/update/special/', views.SpecializedAuthorUpdate.as_view()),
  86. path('edit/author/<int:pk>/delete/naive/', views.NaiveAuthorDelete.as_view()),
  87. path(
  88. 'edit/author/<int:pk>/delete/redirect/',
  89. views.NaiveAuthorDelete.as_view(success_url='/edit/authors/create/'),
  90. ),
  91. path(
  92. 'edit/author/<int:pk>/delete/interpolate_redirect/',
  93. views.NaiveAuthorDelete.as_view(success_url='/edit/authors/create/?deleted={id}')
  94. ),
  95. path(
  96. 'edit/author/<int:pk>/delete/interpolate_redirect_nonascii/',
  97. views.NaiveAuthorDelete.as_view(success_url='/%C3%A9dit/authors/create/?deleted={id}')
  98. ),
  99. path('edit/author/<int:pk>/delete/', views.AuthorDelete.as_view()),
  100. path('edit/author/<int:pk>/delete/special/', views.SpecializedAuthorDelete.as_view()),
  101. # ArchiveIndexView
  102. path('dates/books/', views.BookArchive.as_view()),
  103. path('dates/books/context_object_name/', views.BookArchive.as_view(context_object_name='thingies')),
  104. path('dates/books/allow_empty/', views.BookArchive.as_view(allow_empty=True)),
  105. path('dates/books/template_name/', views.BookArchive.as_view(template_name='generic_views/list.html')),
  106. path('dates/books/template_name_suffix/', views.BookArchive.as_view(template_name_suffix='_detail')),
  107. path('dates/books/invalid/', views.BookArchive.as_view(queryset=None)),
  108. path('dates/books/paginated/', views.BookArchive.as_view(paginate_by=10)),
  109. path('dates/books/reverse/', views.BookArchive.as_view(queryset=Book.objects.order_by('pubdate'))),
  110. path('dates/books/by_month/', views.BookArchive.as_view(date_list_period='month')),
  111. path('dates/booksignings/', views.BookSigningArchive.as_view()),
  112. path('dates/books/sortedbyname/', views.BookArchive.as_view(ordering='name')),
  113. path('dates/books/sortedbynamedec/', views.BookArchive.as_view(ordering='-name')),
  114. path('dates/books/without_date_field/', views.BookArchiveWithoutDateField.as_view()),
  115. # ListView
  116. path('list/dict/', views.DictList.as_view()),
  117. path('list/dict/paginated/', views.DictList.as_view(paginate_by=1)),
  118. path('list/artists/', views.ArtistList.as_view(), name='artists_list'),
  119. path('list/authors/', views.AuthorList.as_view(), name='authors_list'),
  120. path('list/authors/paginated/', views.AuthorList.as_view(paginate_by=30)),
  121. path('list/authors/paginated/<int:page>/', views.AuthorList.as_view(paginate_by=30)),
  122. path('list/authors/paginated-orphaned/', views.AuthorList.as_view(paginate_by=30, paginate_orphans=2)),
  123. path('list/authors/notempty/', views.AuthorList.as_view(allow_empty=False)),
  124. path('list/authors/notempty/paginated/', views.AuthorList.as_view(allow_empty=False, paginate_by=2)),
  125. path('list/authors/template_name/', views.AuthorList.as_view(template_name='generic_views/list.html')),
  126. path('list/authors/template_name_suffix/', views.AuthorList.as_view(template_name_suffix='_objects')),
  127. path('list/authors/context_object_name/', views.AuthorList.as_view(context_object_name='author_list')),
  128. path('list/authors/dupe_context_object_name/', views.AuthorList.as_view(context_object_name='object_list')),
  129. path('list/authors/invalid/', views.AuthorList.as_view(queryset=None)),
  130. path(
  131. 'list/authors/get_queryset/',
  132. views.AuthorListGetQuerysetReturnsNone.as_view(),
  133. ),
  134. path(
  135. 'list/authors/paginated/custom_class/',
  136. views.AuthorList.as_view(paginate_by=5, paginator_class=views.CustomPaginator),
  137. ),
  138. path('list/authors/paginated/custom_page_kwarg/', views.AuthorList.as_view(paginate_by=30, page_kwarg='pagina')),
  139. path('list/authors/paginated/custom_constructor/', views.AuthorListCustomPaginator.as_view()),
  140. path('list/books/sorted/', views.BookList.as_view(ordering='name')),
  141. path('list/books/sortedbypagesandnamedec/', views.BookList.as_view(ordering=('pages', '-name'))),
  142. # YearArchiveView
  143. # Mixing keyword and positional captures below is intentional; the views
  144. # ought to be able to accept either.
  145. path('dates/books/<int:year>/', views.BookYearArchive.as_view()),
  146. path('dates/books/<int:year>/make_object_list/', views.BookYearArchive.as_view(make_object_list=True)),
  147. path('dates/books/<int:year>/allow_empty/', views.BookYearArchive.as_view(allow_empty=True)),
  148. path('dates/books/<int:year>/allow_future/', views.BookYearArchive.as_view(allow_future=True)),
  149. path('dates/books/<int:year>/paginated/', views.BookYearArchive.as_view(make_object_list=True, paginate_by=30)),
  150. path(
  151. 'dates/books/<int:year>/sortedbyname/',
  152. views.BookYearArchive.as_view(make_object_list=True, ordering='name'),
  153. ),
  154. path(
  155. 'dates/books/<int:year>/sortedbypageandnamedec/',
  156. views.BookYearArchive.as_view(make_object_list=True, ordering=('pages', '-name')),
  157. ),
  158. path('dates/books/no_year/', views.BookYearArchive.as_view()),
  159. path('dates/books/<int:year>/reverse/', views.BookYearArchive.as_view(queryset=Book.objects.order_by('pubdate'))),
  160. path('dates/booksignings/<int:year>/', views.BookSigningYearArchive.as_view()),
  161. # MonthArchiveView
  162. path('dates/books/<int:year>/<int:month>/', views.BookMonthArchive.as_view(month_format='%m')),
  163. path('dates/books/<int:year>/<month>/', views.BookMonthArchive.as_view()),
  164. path('dates/books/without_month/<int:year>/', views.BookMonthArchive.as_view()),
  165. path('dates/books/<int:year>/<month>/allow_empty/', views.BookMonthArchive.as_view(allow_empty=True)),
  166. path('dates/books/<int:year>/<month>/allow_future/', views.BookMonthArchive.as_view(allow_future=True)),
  167. path('dates/books/<int:year>/<month>/paginated/', views.BookMonthArchive.as_view(paginate_by=30)),
  168. path('dates/books/<int:year>/no_month/', views.BookMonthArchive.as_view()),
  169. path('dates/booksignings/<int:year>/<month>/', views.BookSigningMonthArchive.as_view()),
  170. # WeekArchiveView
  171. path('dates/books/<int:year>/week/<int:week>/', views.BookWeekArchive.as_view()),
  172. path('dates/books/<int:year>/week/<int:week>/allow_empty/', views.BookWeekArchive.as_view(allow_empty=True)),
  173. path('dates/books/<int:year>/week/<int:week>/allow_future/', views.BookWeekArchive.as_view(allow_future=True)),
  174. path('dates/books/<int:year>/week/<int:week>/paginated/', views.BookWeekArchive.as_view(paginate_by=30)),
  175. path('dates/books/<int:year>/week/no_week/', views.BookWeekArchive.as_view()),
  176. path('dates/books/<int:year>/week/<int:week>/monday/', views.BookWeekArchive.as_view(week_format='%W')),
  177. path(
  178. 'dates/books/<int:year>/week/<int:week>/unknown_week_format/',
  179. views.BookWeekArchive.as_view(week_format='%T'),
  180. ),
  181. path(
  182. 'dates/books/<int:year>/week/<int:week>/iso_format/',
  183. views.BookWeekArchive.as_view(year_format='%G', week_format='%V'),
  184. ),
  185. path(
  186. 'dates/books/<int:year>/week/<int:week>/invalid_iso_week_year_format/',
  187. views.BookWeekArchive.as_view(week_format='%V'),
  188. ),
  189. path('dates/booksignings/<int:year>/week/<int:week>/', views.BookSigningWeekArchive.as_view()),
  190. # DayArchiveView
  191. path('dates/books/<int:year>/<int:month>/<int:day>/', views.BookDayArchive.as_view(month_format='%m')),
  192. path('dates/books/<int:year>/<month>/<int:day>/', views.BookDayArchive.as_view()),
  193. path('dates/books/<int:year>/<month>/<int:day>/allow_empty/', views.BookDayArchive.as_view(allow_empty=True)),
  194. path('dates/books/<int:year>/<month>/<int:day>/allow_future/', views.BookDayArchive.as_view(allow_future=True)),
  195. path(
  196. 'dates/books/<int:year>/<month>/<int:day>/allow_empty_and_future/',
  197. views.BookDayArchive.as_view(allow_empty=True, allow_future=True),
  198. ),
  199. path('dates/books/<int:year>/<month>/<int:day>/paginated/', views.BookDayArchive.as_view(paginate_by=True)),
  200. path('dates/books/<int:year>/<month>/no_day/', views.BookDayArchive.as_view()),
  201. path('dates/booksignings/<int:year>/<month>/<int:day>/', views.BookSigningDayArchive.as_view()),
  202. # TodayArchiveView
  203. path('dates/books/today/', views.BookTodayArchive.as_view()),
  204. path('dates/books/today/allow_empty/', views.BookTodayArchive.as_view(allow_empty=True)),
  205. path('dates/booksignings/today/', views.BookSigningTodayArchive.as_view()),
  206. # DateDetailView
  207. path('dates/books/<int:year>/<int:month>/<day>/<int:pk>/', views.BookDetail.as_view(month_format='%m')),
  208. path('dates/books/<int:year>/<month>/<day>/<int:pk>/', views.BookDetail.as_view()),
  209. path(
  210. 'dates/books/<int:year>/<month>/<int:day>/<int:pk>/allow_future/',
  211. views.BookDetail.as_view(allow_future=True),
  212. ),
  213. path('dates/books/<int:year>/<month>/<int:day>/nopk/', views.BookDetail.as_view()),
  214. path('dates/books/<int:year>/<month>/<int:day>/byslug/<slug:slug>/', views.BookDetail.as_view()),
  215. path(
  216. 'dates/books/get_object_custom_queryset/<int:year>/<month>/<int:day>/<int:pk>/',
  217. views.BookDetailGetObjectCustomQueryset.as_view(),
  218. ),
  219. path('dates/booksignings/<int:year>/<month>/<int:day>/<int:pk>/', views.BookSigningDetail.as_view()),
  220. # Useful for testing redirects
  221. path('accounts/login/', auth_views.LoginView.as_view()),
  222. path('BaseDateListViewTest/', dates.BaseDateListView.as_view()),
  223. ]