| 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 |
|
| 7 |
from . import views |
| 8 |
from .models import Book |
| 9 |
|
| 10 |
urlpatterns = [ |
| 11 |
# TemplateView |
| 12 |
path("template/no_template/", TemplateView.as_view()), |
| 13 |
path("template/login_required/", login_required(TemplateView.as_view())), |
| 14 |
path( |
| 15 |
"template/simple/<foo>/", |
| 16 |
TemplateView.as_view(template_name="generic_views/about.html"), |
| 17 |
), |
| 18 |
path( |
| 19 |
"template/custom/<foo>/", |
| 20 |
views.CustomTemplateView.as_view(template_name="generic_views/about.html"), |
| 21 |
), |
| 22 |
path( |
| 23 |
"template/content_type/", |
| 24 |
TemplateView.as_view( |
| 25 |
template_name="generic_views/robots.txt", content_type="text/plain" |
| 26 |
), |
| 27 |
), |
| 28 |
path( |
| 29 |
"template/cached/<foo>/", |
| 30 |
cache_page(2)(TemplateView.as_view(template_name="generic_views/about.html")), |
| 31 |
), |
| 32 |
path( |
| 33 |
"template/extra_context/", |
| 34 |
TemplateView.as_view( |
| 35 |
template_name="generic_views/about.html", extra_context={"title": "Title"} |
| 36 |
), |
| 37 |
), |
| 38 |
# DetailView |
| 39 |
path("detail/obj/", views.ObjectDetail.as_view()), |
| 40 |
path("detail/artist/<int:pk>/", views.ArtistDetail.as_view(), name="artist_detail"), |
| 41 |
path("detail/author/<int:pk>/", views.AuthorDetail.as_view(), name="author_detail"), |
| 42 |
path( |
| 43 |
"detail/author/bycustompk/<foo>/", |
| 44 |
views.AuthorDetail.as_view(pk_url_kwarg="foo"), |
| 45 |
), |
| 46 |
path("detail/author/byslug/<slug>/", views.AuthorDetail.as_view()), |
| 47 |
path( |
| 48 |
"detail/author/bycustomslug/<foo>/", |
| 49 |
views.AuthorDetail.as_view(slug_url_kwarg="foo"), |
| 50 |
), |
| 51 |
path("detail/author/bypkignoreslug/<int:pk>-<slug>/", views.AuthorDetail.as_view()), |
| 52 |
path( |
| 53 |
"detail/author/bypkandslug/<int:pk>-<slug>/", |
| 54 |
views.AuthorDetail.as_view(query_pk_and_slug=True), |
| 55 |
), |
| 56 |
path( |
| 57 |
"detail/author/<int:pk>/template_name_suffix/", |
| 58 |
views.AuthorDetail.as_view(template_name_suffix="_view"), |
| 59 |
), |
| 60 |
path( |
| 61 |
"detail/author/<int:pk>/template_name/", |
| 62 |
views.AuthorDetail.as_view(template_name="generic_views/about.html"), |
| 63 |
), |
| 64 |
path( |
| 65 |
"detail/author/<int:pk>/context_object_name/", |
| 66 |
views.AuthorDetail.as_view(context_object_name="thingy"), |
| 67 |
), |
| 68 |
path("detail/author/<int:pk>/custom_detail/", views.AuthorCustomDetail.as_view()), |
| 69 |
path( |
| 70 |
"detail/author/<int:pk>/dupe_context_object_name/", |
| 71 |
views.AuthorDetail.as_view(context_object_name="object"), |
| 72 |
), |
| 73 |
path("detail/page/<int:pk>/field/", views.PageDetail.as_view()), |
| 74 |
path(r"detail/author/invalid/url/", views.AuthorDetail.as_view()), |
| 75 |
path("detail/author/invalid/qs/", views.AuthorDetail.as_view(queryset=None)), |
| 76 |
path("detail/nonmodel/1/", views.NonModelDetail.as_view()), |
| 77 |
path("detail/doesnotexist/<pk>/", views.ObjectDoesNotExistDetail.as_view()), |
| 78 |
# FormView |
| 79 |
path("contact/", views.ContactView.as_view()), |
| 80 |
path("late-validation/", views.LateValidationView.as_view()), |
| 81 |
# Create/UpdateView |
| 82 |
path("edit/artists/create/", views.ArtistCreate.as_view()), |
| 83 |
path("edit/artists/<int:pk>/update/", views.ArtistUpdate.as_view()), |
| 84 |
path("edit/authors/create/naive/", views.NaiveAuthorCreate.as_view()), |
| 85 |
path( |
| 86 |
"edit/authors/create/redirect/", |
| 87 |
views.NaiveAuthorCreate.as_view(success_url="/edit/authors/create/"), |
| 88 |
), |
| 89 |
path( |
| 90 |
"edit/authors/create/interpolate_redirect/", |
| 91 |
views.NaiveAuthorCreate.as_view(success_url="/edit/author/{id}/update/"), |
| 92 |
), |
| 93 |
path( |
| 94 |
"edit/authors/create/interpolate_redirect_nonascii/", |
| 95 |
views.NaiveAuthorCreate.as_view(success_url="/%C3%A9dit/author/{id}/update/"), |
| 96 |
), |
| 97 |
path("edit/authors/create/restricted/", views.AuthorCreateRestricted.as_view()), |
| 98 |
re_path("^[eé]dit/authors/create/$", views.AuthorCreate.as_view()), |
| 99 |
path("edit/authors/create/special/", views.SpecializedAuthorCreate.as_view()), |
| 100 |
path("edit/author/<int:pk>/update/naive/", views.NaiveAuthorUpdate.as_view()), |
| 101 |
path( |
| 102 |
"edit/author/<int:pk>/update/redirect/", |
| 103 |
views.NaiveAuthorUpdate.as_view(success_url="/edit/authors/create/"), |
| 104 |
), |
| 105 |
path( |
| 106 |
"edit/author/<int:pk>/update/interpolate_redirect/", |
| 107 |
views.NaiveAuthorUpdate.as_view(success_url="/edit/author/{id}/update/"), |
| 108 |
), |
| 109 |
path( |
| 110 |
"edit/author/<int:pk>/update/interpolate_redirect_nonascii/", |
| 111 |
views.NaiveAuthorUpdate.as_view(success_url="/%C3%A9dit/author/{id}/update/"), |
| 112 |
), |
| 113 |
re_path("^[eé]dit/author/(?P<pk>[0-9]+)/update/$", views.AuthorUpdate.as_view()), |
| 114 |
path("edit/author/update/", views.OneAuthorUpdate.as_view()), |
| 115 |
path( |
| 116 |
"edit/author/<int:pk>/update/special/", views.SpecializedAuthorUpdate.as_view() |
| 117 |
), |
| 118 |
path("edit/author/<int:pk>/delete/naive/", views.NaiveAuthorDelete.as_view()), |
| 119 |
path( |
| 120 |
"edit/author/<int:pk>/delete/redirect/", |
| 121 |
views.NaiveAuthorDelete.as_view(success_url="/edit/authors/create/"), |
| 122 |
), |
| 123 |
path( |
| 124 |
"edit/author/<int:pk>/delete/interpolate_redirect/", |
| 125 |
views.NaiveAuthorDelete.as_view( |
| 126 |
success_url="/edit/authors/create/?deleted={id}" |
| 127 |
), |
| 128 |
), |
| 129 |
path( |
| 130 |
"edit/author/<int:pk>/delete/interpolate_redirect_nonascii/", |
| 131 |
views.NaiveAuthorDelete.as_view( |
| 132 |
success_url="/%C3%A9dit/authors/create/?deleted={id}" |
| 133 |
), |
| 134 |
), |
| 135 |
path("edit/author/<int:pk>/delete/", views.AuthorDelete.as_view()), |
| 136 |
path( |
| 137 |
"edit/author/<int:pk>/delete/special/", views.SpecializedAuthorDelete.as_view() |
| 138 |
), |
| 139 |
path("edit/author/<int:pk>/delete/form/", views.AuthorDeleteFormView.as_view()), |
| 140 |
# ArchiveIndexView |
| 141 |
path("dates/books/", views.BookArchive.as_view()), |
| 142 |
path( |
| 143 |
"dates/books/context_object_name/", |
| 144 |
views.BookArchive.as_view(context_object_name="thingies"), |
| 145 |
), |
| 146 |
path("dates/books/allow_empty/", views.BookArchive.as_view(allow_empty=True)), |
| 147 |
path( |
| 148 |
"dates/books/template_name/", |
| 149 |
views.BookArchive.as_view(template_name="generic_views/list.html"), |
| 150 |
), |
| 151 |
path( |
| 152 |
"dates/books/template_name_suffix/", |
| 153 |
views.BookArchive.as_view(template_name_suffix="_detail"), |
| 154 |
), |
| 155 |
path("dates/books/invalid/", views.BookArchive.as_view(queryset=None)), |
| 156 |
path("dates/books/paginated/", views.BookArchive.as_view(paginate_by=10)), |
| 157 |
path( |
| 158 |
"dates/books/reverse/", |
| 159 |
views.BookArchive.as_view(queryset=Book.objects.order_by("pubdate")), |
| 160 |
), |
| 161 |
path("dates/books/by_month/", views.BookArchive.as_view(date_list_period="month")), |
| 162 |
path("dates/booksignings/", views.BookSigningArchive.as_view()), |
| 163 |
path("dates/books/sortedbyname/", views.BookArchive.as_view(ordering="name")), |
| 164 |
path("dates/books/sortedbynamedec/", views.BookArchive.as_view(ordering="-name")), |
| 165 |
path( |
| 166 |
"dates/books/without_date_field/", views.BookArchiveWithoutDateField.as_view() |
| 167 |
), |
| 168 |
# ListView |
| 169 |
path("list/dict/", views.DictList.as_view()), |
| 170 |
path("list/dict/paginated/", views.DictList.as_view(paginate_by=1)), |
| 171 |
path("list/artists/", views.ArtistList.as_view(), name="artists_list"), |
| 172 |
path("list/authors/", views.AuthorList.as_view(), name="authors_list"), |
| 173 |
path("list/authors/paginated/", views.AuthorList.as_view(paginate_by=30)), |
| 174 |
path( |
| 175 |
"list/authors/paginated/<int:page>/", views.AuthorList.as_view(paginate_by=30) |
| 176 |
), |
| 177 |
path( |
| 178 |
"list/authors/paginated-orphaned/", |
| 179 |
views.AuthorList.as_view(paginate_by=30, paginate_orphans=2), |
| 180 |
), |
| 181 |
path("list/authors/notempty/", views.AuthorList.as_view(allow_empty=False)), |
| 182 |
path( |
| 183 |
"list/authors/notempty/paginated/", |
| 184 |
views.AuthorList.as_view(allow_empty=False, paginate_by=2), |
| 185 |
), |
| 186 |
path( |
| 187 |
"list/authors/template_name/", |
| 188 |
views.AuthorList.as_view(template_name="generic_views/list.html"), |
| 189 |
), |
| 190 |
path( |
| 191 |
"list/authors/template_name_suffix/", |
| 192 |
views.AuthorList.as_view(template_name_suffix="_objects"), |
| 193 |
), |
| 194 |
path( |
| 195 |
"list/authors/context_object_name/", |
| 196 |
views.AuthorList.as_view(context_object_name="author_list"), |
| 197 |
), |
| 198 |
path( |
| 199 |
"list/authors/dupe_context_object_name/", |
| 200 |
views.AuthorList.as_view(context_object_name="object_list"), |
| 201 |
), |
| 202 |
path("list/authors/invalid/", views.AuthorList.as_view(queryset=None)), |
| 203 |
path( |
| 204 |
"list/authors/get_queryset/", |
| 205 |
views.AuthorListGetQuerysetReturnsNone.as_view(), |
| 206 |
), |
| 207 |
path( |
| 208 |
"list/authors/paginated/custom_class/", |
| 209 |
views.AuthorList.as_view(paginate_by=5, paginator_class=views.CustomPaginator), |
| 210 |
), |
| 211 |
path( |
| 212 |
"list/authors/paginated/custom_page_kwarg/", |
| 213 |
views.AuthorList.as_view(paginate_by=30, page_kwarg="pagina"), |
| 214 |
), |
| 215 |
path( |
| 216 |
"list/authors/paginated/custom_constructor/", |
| 217 |
views.AuthorListCustomPaginator.as_view(), |
| 218 |
), |
| 219 |
path("list/books/sorted/", views.BookList.as_view(ordering="name")), |
| 220 |
path( |
| 221 |
"list/books/sortedbypagesandnamedec/", |
| 222 |
views.BookList.as_view(ordering=("pages", "-name")), |
| 223 |
), |
| 224 |
# YearArchiveView |
| 225 |
# Mixing keyword and positional captures below is intentional; the views |
| 226 |
# ought to be able to accept either. |
| 227 |
path("dates/books/<int:year>/", views.BookYearArchive.as_view()), |
| 228 |
path( |
| 229 |
"dates/books/<int:year>/make_object_list/", |
| 230 |
views.BookYearArchive.as_view(make_object_list=True), |
| 231 |
), |
| 232 |
path( |
| 233 |
"dates/books/<int:year>/allow_empty/", |
| 234 |
views.BookYearArchive.as_view(allow_empty=True), |
| 235 |
), |
| 236 |
path( |
| 237 |
"dates/books/<int:year>/allow_future/", |
| 238 |
views.BookYearArchive.as_view(allow_future=True), |
| 239 |
), |
| 240 |
path( |
| 241 |
"dates/books/<int:year>/paginated/", |
| 242 |
views.BookYearArchive.as_view(make_object_list=True, paginate_by=30), |
| 243 |
), |
| 244 |
path( |
| 245 |
"dates/books/<int:year>/sortedbyname/", |
| 246 |
views.BookYearArchive.as_view(make_object_list=True, ordering="name"), |
| 247 |
), |
| 248 |
path( |
| 249 |
"dates/books/<int:year>/sortedbypageandnamedec/", |
| 250 |
views.BookYearArchive.as_view( |
| 251 |
make_object_list=True, ordering=("pages", "-name") |
| 252 |
), |
| 253 |
), |
| 254 |
path("dates/books/no_year/", views.BookYearArchive.as_view()), |
| 255 |
path( |
| 256 |
"dates/books/<int:year>/reverse/", |
| 257 |
views.BookYearArchive.as_view(queryset=Book.objects.order_by("pubdate")), |
| 258 |
), |
| 259 |
path("dates/booksignings/<int:year>/", views.BookSigningYearArchive.as_view()), |
| 260 |
# MonthArchiveView |
| 261 |
path( |
| 262 |
"dates/books/<int:year>/<int:month>/", |
| 263 |
views.BookMonthArchive.as_view(month_format="%m"), |
| 264 |
), |
| 265 |
path("dates/books/<int:year>/<month>/", views.BookMonthArchive.as_view()), |
| 266 |
path("dates/books/without_month/<int:year>/", views.BookMonthArchive.as_view()), |
| 267 |
path( |
| 268 |
"dates/books/<int:year>/<month>/allow_empty/", |
| 269 |
views.BookMonthArchive.as_view(allow_empty=True), |
| 270 |
), |
| 271 |
path( |
| 272 |
"dates/books/<int:year>/<month>/allow_future/", |
| 273 |
views.BookMonthArchive.as_view(allow_future=True), |
| 274 |
), |
| 275 |
path( |
| 276 |
"dates/books/<int:year>/<month>/paginated/", |
| 277 |
views.BookMonthArchive.as_view(paginate_by=30), |
| 278 |
), |
| 279 |
path("dates/books/<int:year>/no_month/", views.BookMonthArchive.as_view()), |
| 280 |
path( |
| 281 |
"dates/booksignings/<int:year>/<month>/", |
| 282 |
views.BookSigningMonthArchive.as_view(), |
| 283 |
), |
| 284 |
# WeekArchiveView |
| 285 |
path("dates/books/<int:year>/week/<int:week>/", views.BookWeekArchive.as_view()), |
| 286 |
path( |
| 287 |
"dates/books/<int:year>/week/<int:week>/allow_empty/", |
| 288 |
views.BookWeekArchive.as_view(allow_empty=True), |
| 289 |
), |
| 290 |
path( |
| 291 |
"dates/books/<int:year>/week/<int:week>/allow_future/", |
| 292 |
views.BookWeekArchive.as_view(allow_future=True), |
| 293 |
), |
| 294 |
path( |
| 295 |
"dates/books/<int:year>/week/<int:week>/paginated/", |
| 296 |
views.BookWeekArchive.as_view(paginate_by=30), |
| 297 |
), |
| 298 |
path("dates/books/<int:year>/week/no_week/", views.BookWeekArchive.as_view()), |
| 299 |
path( |
| 300 |
"dates/books/<int:year>/week/<int:week>/monday/", |
| 301 |
views.BookWeekArchive.as_view(week_format="%W"), |
| 302 |
), |
| 303 |
path( |
| 304 |
"dates/books/<int:year>/week/<int:week>/unknown_week_format/", |
| 305 |
views.BookWeekArchive.as_view(week_format="%T"), |
| 306 |
), |
| 307 |
path( |
| 308 |
"dates/books/<int:year>/week/<int:week>/iso_format/", |
| 309 |
views.BookWeekArchive.as_view(year_format="%G", week_format="%V"), |
| 310 |
), |
| 311 |
path( |
| 312 |
"dates/books/<int:year>/week/<int:week>/invalid_iso_week_year_format/", |
| 313 |
views.BookWeekArchive.as_view(week_format="%V"), |
| 314 |
), |
| 315 |
path( |
| 316 |
"dates/booksignings/<int:year>/week/<int:week>/", |
| 317 |
views.BookSigningWeekArchive.as_view(), |
| 318 |
), |
| 319 |
# DayArchiveView |
| 320 |
path( |
| 321 |
"dates/books/<int:year>/<int:month>/<int:day>/", |
| 322 |
views.BookDayArchive.as_view(month_format="%m"), |
| 323 |
), |
| 324 |
path("dates/books/<int:year>/<month>/<int:day>/", views.BookDayArchive.as_view()), |
| 325 |
path( |
| 326 |
"dates/books/<int:year>/<month>/<int:day>/allow_empty/", |
| 327 |
views.BookDayArchive.as_view(allow_empty=True), |
| 328 |
), |
| 329 |
path( |
| 330 |
"dates/books/<int:year>/<month>/<int:day>/allow_future/", |
| 331 |
views.BookDayArchive.as_view(allow_future=True), |
| 332 |
), |
| 333 |
path( |
| 334 |
"dates/books/<int:year>/<month>/<int:day>/allow_empty_and_future/", |
| 335 |
views.BookDayArchive.as_view(allow_empty=True, allow_future=True), |
| 336 |
), |
| 337 |
path( |
| 338 |
"dates/books/<int:year>/<month>/<int:day>/paginated/", |
| 339 |
views.BookDayArchive.as_view(paginate_by=True), |
| 340 |
), |
| 341 |
path("dates/books/<int:year>/<month>/no_day/", views.BookDayArchive.as_view()), |
| 342 |
path( |
| 343 |
"dates/booksignings/<int:year>/<month>/<int:day>/", |
| 344 |
views.BookSigningDayArchive.as_view(), |
| 345 |
), |
| 346 |
# TodayArchiveView |
| 347 |
path("dates/books/today/", views.BookTodayArchive.as_view()), |
| 348 |
path( |
| 349 |
"dates/books/today/allow_empty/", |
| 350 |
views.BookTodayArchive.as_view(allow_empty=True), |
| 351 |
), |
| 352 |
path("dates/booksignings/today/", views.BookSigningTodayArchive.as_view()), |
| 353 |
# DateDetailView |
| 354 |
path( |
| 355 |
"dates/books/<int:year>/<int:month>/<day>/<int:pk>/", |
| 356 |
views.BookDetail.as_view(month_format="%m"), |
| 357 |
), |
| 358 |
path("dates/books/<int:year>/<month>/<day>/<int:pk>/", views.BookDetail.as_view()), |
| 359 |
path( |
| 360 |
"dates/books/<int:year>/<month>/<int:day>/<int:pk>/allow_future/", |
| 361 |
views.BookDetail.as_view(allow_future=True), |
| 362 |
), |
| 363 |
path("dates/books/<int:year>/<month>/<int:day>/nopk/", views.BookDetail.as_view()), |
| 364 |
path( |
| 365 |
"dates/books/<int:year>/<month>/<int:day>/byslug/<slug:slug>/", |
| 366 |
views.BookDetail.as_view(), |
| 367 |
), |
| 368 |
path( |
| 369 |
"dates/books/get_object_custom_queryset/<int:year>/<month>/<int:day>/<int:pk>/", |
| 370 |
views.BookDetailGetObjectCustomQueryset.as_view(), |
| 371 |
), |
| 372 |
path( |
| 373 |
"dates/booksignings/<int:year>/<month>/<int:day>/<int:pk>/", |
| 374 |
views.BookSigningDetail.as_view(), |
| 375 |
), |
| 376 |
# Useful for testing redirects |
| 377 |
path("accounts/login/", auth_views.LoginView.as_view()), |
| 378 |
path("BaseDateListViewTest/", dates.BaseDateListView.as_view()), |
| 379 |
] |