[PATCH v2 2/9] urls: Use new login/password change CBVs
Stephen Finucane
stephen at that.guru
Thu Nov 2 21:28:37 AEDT 2017
The function based views are deprecated in Django 1.11 [1], so support
the newer class based views.
[1] https://docs.djangoproject.com/en/dev/releases/1.11/#id2
Signed-off-by: Stephen Finucane <stephen at that.guru>
---
patchwork/urls.py | 94 +++++++++++++++++++++++++++++++++++++++++--------------
1 file changed, 70 insertions(+), 24 deletions(-)
diff --git a/patchwork/urls.py b/patchwork/urls.py
index 285d5659..b33b01c4 100644
--- a/patchwork/urls.py
+++ b/patchwork/urls.py
@@ -17,11 +17,13 @@
# along with Patchwork; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+import django
from django.conf import settings
from django.conf.urls import url, include
from django.contrib import admin
from django.contrib.auth import views as auth_views
+from patchwork.compat import reverse
from patchwork.views import about as about_views
from patchwork.views import api as api_views
from patchwork.views import bundle as bundle_views
@@ -85,32 +87,75 @@ urlpatterns = [
name='user-link'),
url(r'^user/unlink/(?P<person_id>[^/]+)/$', user_views.unlink,
name='user-unlink'),
+]
- # password change
- url(r'^user/password-change/$', auth_views.password_change,
- name='password_change'),
- url(r'^user/password-change/done/$', auth_views.password_change_done,
- name='password_change_done'),
- url(r'^user/password-reset/$', auth_views.password_reset,
- name='password_reset'),
- url(r'^user/password-reset/mail-sent/$', auth_views.password_reset_done,
- name='password_reset_done'),
- url(r'^user/password-reset/(?P<uidb64>[0-9A-Za-z_\-]+)/'
- r'(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$',
- auth_views.password_reset_confirm,
- name='password_reset_confirm'),
- url(r'^user/password-reset/complete/$',
- auth_views.password_reset_complete,
- name='password_reset_complete'),
-
- # login/logout
- url(r'^user/login/$', auth_views.login,
- {'template_name': 'patchwork/login.html'},
- name='auth_login'),
- url(r'^user/logout/$', auth_views.logout,
- {'next_page': '/'},
- name='auth_logout'),
+# password change
+if django.VERSION > (1, 11):
+ urlpatterns += [
+ url(r'^user/password-change/$',
+ auth_views.PasswordChangeView.as_view(),
+ name='password_change'),
+ url(r'^user/password-change/done/$',
+ auth_views.PasswordChangeDoneView.as_view(),
+ name='password_change_done'),
+ url(r'^user/password-reset/$',
+ auth_views.PasswordResetView.as_view(),
+ name='password_reset'),
+ url(r'^user/password-reset/mail-sent/$',
+ auth_views.PasswordResetDoneView.as_view(),
+ name='password_reset_done'),
+ url(r'^user/password-reset/(?P<uidb64>[0-9A-Za-z_\-]+)/'
+ r'(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$',
+ auth_views.PasswordResetConfirmView.as_view(),
+ name='password_reset_confirm'),
+ url(r'^user/password-reset/complete/$',
+ auth_views.PasswordResetCompleteView.as_view(),
+ name='password_reset_complete'),
+ ]
+else:
+ urlpatterns += [
+ url(r'^user/password-change/$',
+ auth_views.password_change,
+ name='password_change'),
+ url(r'^user/password-change/done/$',
+ auth_views.password_change_done,
+ name='password_change_done'),
+ url(r'^user/password-reset/$',
+ auth_views.password_reset,
+ name='password_reset'),
+ url(r'^user/password-reset/mail-sent/$',
+ auth_views.password_reset_done,
+ name='password_reset_done'),
+ url(r'^user/password-reset/(?P<uidb64>[0-9A-Za-z_\-]+)/'
+ r'(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$',
+ auth_views.password_reset_confirm,
+ name='password_reset_confirm'),
+ url(r'^user/password-reset/complete/$',
+ auth_views.password_reset_complete,
+ name='password_reset_complete'),
+ ]
+# login/logout
+if django.VERSION >= (1, 11):
+ urlpatterns += [
+ url(r'^user/login/$', auth_views.LoginView.as_view(
+ template_name='patchwork/login.html'),
+ name='auth_login'),
+ url(r'^user/logout/$', auth_views.LogoutView.as_view(
+ next_page=reverse('project-list')),
+ name='auth_logout'),
+ ]
+else:
+ urlpatterns += [
+ url(r'^user/login/$', auth_views.login,
+ {'template_name': 'patchwork/login.html'},
+ name='auth_login'),
+ url(r'^user/logout/$', auth_views.logout,
+ {'next_page': reverse('project-list')},
+ name='auth_logout'),
+ ]
+
+urlpatterns += [
# registration
url(r'^register/', user_views.register, name='user-register'),
@@ -144,6 +189,7 @@ urlpatterns = [
if 'debug_toolbar' in settings.INSTALLED_APPS:
import debug_toolbar
+
urlpatterns += [
url(r'^__debug__/', include(debug_toolbar.urls)),
]
--
2.13.6
More information about the Patchwork
mailing list