diff --git a/mainsite/urls.py b/mainsite/urls.py index b98c4c7..e268c41 100644 --- a/mainsite/urls.py +++ b/mainsite/urls.py @@ -1,20 +1,33 @@ -from django.conf.urls import url +from django.urls import path, register_converter from . import views + +class FourDigitYearConverter: + regex = "[0-9]{4}" + + def to_python(self, value): + return int(value) + + def to_url(self, value): + return "%04d" % value + + +register_converter(FourDigitYearConverter, "yyyy") + urlpatterns = [ - url(r"^$", views.HomeView.as_view(), name="homepage"), - url(r"^robots.txt$", views.robots_view, name="robots"), - url(r"^ecrire$", views.WriteArticleView.as_view(), name="write_article"), - url( - r"^speciaux/", + path("", views.HomeView.as_view(), name="homepage"), + path("robots.txt", views.robots_view, name="robots"), + path("ecrire/", views.WriteArticleView.as_view(), name="write_article"), + path( + "speciaux/", views.SpecialPublicationsView.as_view(), name="special_publications", ), - url( - r"^(?P\d{4})-(?P\d{4})/", + path( + "-/", views.YearView.as_view(), name="year_view", ), - url(r"^latest$", views.latestPublication, name="latestPublication"), + path("latest/", views.latestPublication, name="latestPublication"), ]