[{"id":1805544,"web_url":"http://patchwork.ozlabs.org/comment/1805544/","msgid":"<87d14io86i.fsf@linkitivity.dja.id.au>","list_archive_url":null,"date":"2017-11-16T09:59:49","subject":"Re: [PATCH v2 2/9] urls: Use new login/password change CBVs","submitter":{"id":65792,"url":"http://patchwork.ozlabs.org/api/people/65792/","name":"Daniel Axtens","email":"dja@axtens.net"},"content":"Hi Stephen,\n\nI have 2 changes:\n - fixed a > where >= was probably intended\n - use reverse_lazy in url patterns - fixes a bug in my testing, see:\n     https://docs.djangoproject.com/en/1.11/ref/urlresolvers/#reverse-lazy\n     http://www.boxtricks.com/keyerror-en-us-when-doing-a-reverse-lookup-in-urls-py/\n\nThe following diff on top of your patch should be sufficient, apart from\nthat it looks good to me. Feel free to add my Signed-off to this patch\nif you apply it.\n\ndiff --git a/patchwork/compat.py b/patchwork/compat.py\nindex 38a844d93d03..b609aab487ca 100644\n--- a/patchwork/compat.py\n+++ b/patchwork/compat.py\n@@ -86,9 +86,11 @@ if settings.ENABLE_REST_API:\n if django.VERSION >= (1, 10):\n     from django.urls import NoReverseMatch  # noqa\n     from django.urls import reverse  # noqa\n+    from django.urls import reverse_lazy  # noqa\n else:\n     from django.core.urlresolvers import NoReverseMatch  # noqa\n     from django.core.urlresolvers import reverse  # noqa\n+    from django.core.urlresolvers import reverse_lazy  # noqa\ndiff --git a/patchwork/urls.py b/patchwork/urls.py\nindex 6d49d648f635..719347220a86 100644\n--- a/patchwork/urls.py\n+++ b/patchwork/urls.py\n@@ -23,7 +23,7 @@ from django.conf.urls import url, include\n from django.contrib import admin\n from django.contrib.auth import views as auth_views\n \n-from patchwork.compat import reverse\n+from patchwork.compat import reverse_lazy\n from patchwork.views import about as about_views\n from patchwork.views import api as api_views\n from patchwork.views import bundle as bundle_views\n@@ -90,7 +90,7 @@ urlpatterns = [\n ]\n \n # password change\n-if django.VERSION > (1, 11):\n+if django.VERSION >= (1, 11):\n     urlpatterns += [\n         url(r'^user/password-change/$',\n             auth_views.PasswordChangeView.as_view(),\n@@ -142,7 +142,7 @@ if django.VERSION >= (1, 11):\n             template_name='patchwork/login.html'),\n             name='auth_login'),\n         url(r'^user/logout/$', auth_views.LogoutView.as_view(\n-            next_page=reverse('project-list')),\n+            next_page=reverse_lazy('project-list')),\n             name='auth_logout'),\n     ]\n else:\n@@ -151,7 +151,7 @@ else:\n             {'template_name': 'patchwork/login.html'},\n             name='auth_login'),\n         url(r'^user/logout/$', auth_views.logout,\n-            {'next_page': reverse('project-list')},\n+            {'next_page': reverse_lazy('project-list')},\n             name='auth_logout'),\n     ]\n\n\n> The function based views are deprecated in Django 1.11 [1], so support\n> the newer class based views.\n>\n> [1] https://docs.djangoproject.com/en/dev/releases/1.11/#id2\n>\n> Signed-off-by: Stephen Finucane <stephen@that.guru>\n> ---\n>  patchwork/urls.py | 94 +++++++++++++++++++++++++++++++++++++++++--------------\n>  1 file changed, 70 insertions(+), 24 deletions(-)\n>\n> diff --git a/patchwork/urls.py b/patchwork/urls.py\n> index 285d5659..b33b01c4 100644\n> --- a/patchwork/urls.py\n> +++ b/patchwork/urls.py\n> @@ -17,11 +17,13 @@\n>  # along with Patchwork; if not, write to the Free Software\n>  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\n>  \n> +import django\n>  from django.conf import settings\n>  from django.conf.urls import url, include\n>  from django.contrib import admin\n>  from django.contrib.auth import views as auth_views\n>  \n> +from patchwork.compat import reverse\n>  from patchwork.views import about as about_views\n>  from patchwork.views import api as api_views\n>  from patchwork.views import bundle as bundle_views\n> @@ -85,32 +87,75 @@ urlpatterns = [\n>          name='user-link'),\n>      url(r'^user/unlink/(?P<person_id>[^/]+)/$', user_views.unlink,\n>          name='user-unlink'),\n> +]\n>  \n> -    # password change\n> -    url(r'^user/password-change/$', auth_views.password_change,\n> -        name='password_change'),\n> -    url(r'^user/password-change/done/$', auth_views.password_change_done,\n> -        name='password_change_done'),\n> -    url(r'^user/password-reset/$', auth_views.password_reset,\n> -        name='password_reset'),\n> -    url(r'^user/password-reset/mail-sent/$', auth_views.password_reset_done,\n> -        name='password_reset_done'),\n> -    url(r'^user/password-reset/(?P<uidb64>[0-9A-Za-z_\\-]+)/'\n> -        r'(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$',\n> -        auth_views.password_reset_confirm,\n> -        name='password_reset_confirm'),\n> -    url(r'^user/password-reset/complete/$',\n> -        auth_views.password_reset_complete,\n> -        name='password_reset_complete'),\n> -\n> -    # login/logout\n> -    url(r'^user/login/$', auth_views.login,\n> -        {'template_name': 'patchwork/login.html'},\n> -        name='auth_login'),\n> -    url(r'^user/logout/$', auth_views.logout,\n> -        {'next_page': '/'},\n> -        name='auth_logout'),\n> +# password change\n> +if django.VERSION > (1, 11):\n> +    urlpatterns += [\n> +        url(r'^user/password-change/$',\n> +            auth_views.PasswordChangeView.as_view(),\n> +            name='password_change'),\n> +        url(r'^user/password-change/done/$',\n> +            auth_views.PasswordChangeDoneView.as_view(),\n> +            name='password_change_done'),\n> +        url(r'^user/password-reset/$',\n> +            auth_views.PasswordResetView.as_view(),\n> +            name='password_reset'),\n> +        url(r'^user/password-reset/mail-sent/$',\n> +            auth_views.PasswordResetDoneView.as_view(),\n> +            name='password_reset_done'),\n> +        url(r'^user/password-reset/(?P<uidb64>[0-9A-Za-z_\\-]+)/'\n> +            r'(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$',\n> +            auth_views.PasswordResetConfirmView.as_view(),\n> +            name='password_reset_confirm'),\n> +        url(r'^user/password-reset/complete/$',\n> +            auth_views.PasswordResetCompleteView.as_view(),\n> +            name='password_reset_complete'),\n> +    ]\n> +else:\n> +    urlpatterns += [\n> +        url(r'^user/password-change/$',\n> +            auth_views.password_change,\n> +            name='password_change'),\n> +        url(r'^user/password-change/done/$',\n> +            auth_views.password_change_done,\n> +            name='password_change_done'),\n> +        url(r'^user/password-reset/$',\n> +            auth_views.password_reset,\n> +            name='password_reset'),\n> +        url(r'^user/password-reset/mail-sent/$',\n> +            auth_views.password_reset_done,\n> +            name='password_reset_done'),\n> +        url(r'^user/password-reset/(?P<uidb64>[0-9A-Za-z_\\-]+)/'\n> +            r'(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$',\n> +            auth_views.password_reset_confirm,\n> +            name='password_reset_confirm'),\n> +        url(r'^user/password-reset/complete/$',\n> +            auth_views.password_reset_complete,\n> +            name='password_reset_complete'),\n> +    ]\n>  \n> +# login/logout\n> +if django.VERSION >= (1, 11):\n> +    urlpatterns += [\n> +        url(r'^user/login/$', auth_views.LoginView.as_view(\n> +            template_name='patchwork/login.html'),\n> +            name='auth_login'),\n> +        url(r'^user/logout/$', auth_views.LogoutView.as_view(\n> +            next_page=reverse('project-list')),\n> +            name='auth_logout'),\n> +    ]\n> +else:\n> +    urlpatterns += [\n> +        url(r'^user/login/$', auth_views.login,\n> +            {'template_name': 'patchwork/login.html'},\n> +            name='auth_login'),\n> +        url(r'^user/logout/$', auth_views.logout,\n> +            {'next_page': reverse('project-list')},\n> +            name='auth_logout'),\n> +    ]\n> +\n> +urlpatterns += [\n>      # registration\n>      url(r'^register/', user_views.register, name='user-register'),\n>  \n> @@ -144,6 +189,7 @@ urlpatterns = [\n>  \n>  if 'debug_toolbar' in settings.INSTALLED_APPS:\n>      import debug_toolbar\n> +\n>      urlpatterns += [\n>          url(r'^__debug__/', include(debug_toolbar.urls)),\n>      ]\n> -- \n> 2.13.6\n>\n> _______________________________________________\n> Patchwork mailing list\n> Patchwork@lists.ozlabs.org\n> https://lists.ozlabs.org/listinfo/patchwork","headers":{"Return-Path":"<patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org>","X-Original-To":["incoming@patchwork.ozlabs.org","patchwork@lists.ozlabs.org"],"Delivered-To":["patchwork-incoming@bilbo.ozlabs.org","patchwork@lists.ozlabs.org"],"Received":["from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3])\n\t(using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3ycxYs3nPzz9t62\n\tfor <incoming@patchwork.ozlabs.org>;\n\tThu, 16 Nov 2017 21:00:01 +1100 (AEDT)","from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3])\n\tby lists.ozlabs.org (Postfix) with ESMTP id 3ycxYs1jdpzDr0W\n\tfor <incoming@patchwork.ozlabs.org>;\n\tThu, 16 Nov 2017 21:00:01 +1100 (AEDT)","from mail-pg0-x244.google.com (mail-pg0-x244.google.com\n\t[IPv6:2607:f8b0:400e:c05::244])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128\n\tbits)) (No client certificate requested)\n\tby lists.ozlabs.org (Postfix) with ESMTPS id 3ycxYl4sJwzDqvB\n\tfor <patchwork@lists.ozlabs.org>;\n\tThu, 16 Nov 2017 20:59:55 +1100 (AEDT)","by mail-pg0-x244.google.com with SMTP id s11so14764238pgc.5\n\tfor <patchwork@lists.ozlabs.org>;\n\tThu, 16 Nov 2017 01:59:55 -0800 (PST)","from localhost (ppp121-45-207-150.bras1.cbr1.internode.on.net.\n\t[121.45.207.150]) by smtp.gmail.com with ESMTPSA id\n\tj8sm2512415pff.131.2017.11.16.01.59.52\n\t(version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);\n\tThu, 16 Nov 2017 01:59:52 -0800 (PST)"],"Authentication-Results":["ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=axtens.net header.i=@axtens.net\n\theader.b=\"HyCfe1Rv\"; dkim-atps=neutral","lists.ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=axtens.net header.i=@axtens.net\n\theader.b=\"HyCfe1Rv\"; dkim-atps=neutral","ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=axtens.net\n\t(client-ip=2607:f8b0:400e:c05::244; helo=mail-pg0-x244.google.com;\n\tenvelope-from=dja@axtens.net; receiver=<UNKNOWN>)","lists.ozlabs.org; dkim=pass (1024-bit key;\n\tunprotected) header.d=axtens.net header.i=@axtens.net\n\theader.b=\"HyCfe1Rv\"; dkim-atps=neutral"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=axtens.net; s=google;\n\th=from:to:subject:in-reply-to:references:date:message-id:mime-version;\n\tbh=9rrdrNdtQzLdO3HcKpSZKeEW2b+FdkXeB+xUbEPt2No=;\n\tb=HyCfe1RvaCsVMHT3siDXCpKkZXqWoOoCmrXmktjR8nz58RSM3q3492p1ZzPn+UI0br\n\tVWRoXvR2G1sKo9IMIuwWhqjJjV6Y4oWWh7TSrAFCEtgXOgBUg3M+GcQmnj3cXRRKbDxx\n\tFXDbcmHezWXKRXTer4wsvl18qt59h/hNxp1lo=","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:to:subject:in-reply-to:references:date\n\t:message-id:mime-version;\n\tbh=9rrdrNdtQzLdO3HcKpSZKeEW2b+FdkXeB+xUbEPt2No=;\n\tb=VT6pi7nM2Th332FOtrHTsw/nqAPHWcIVy2nO7CefD9s/JrLL8fCaX6yZ+mUr2KdCZd\n\tTsB58nelx0ACPxkzGGKAKyWTrB5WHDRQ/+A4wv1YLZbPAX2UpeSO9y16LMkW3ZwJ1IW4\n\tqJ9UgdMOIFfHGjFqGWbJUrhgAedkkf1CmVCXvotccF9MgNtCnDQ2COnF1kAdfSEu9/LE\n\tTZlMCWXTNPAz1YdhiKdNe2Cw7+/aMRM9PtR26fxklK04B0cxLXeIA+gg+eKcLwO4Q6CI\n\tbisB2sFKnF0pGkGWsieZ4wtC1wPv/1xSYk2TzruQu38Kh9tAT3af/uI/47TYeY6NbplE\n\tczqg==","X-Gm-Message-State":"AJaThX5ah2UJ4blpB9QctIoRHe4bJW1JEm91wVQUKJZzQWgEhZ9MPUvb\n\tJrbIJi8r2dogxYqJaM1IUYSbJQ==","X-Google-Smtp-Source":"AGs4zMY2ub3dnHj2qpXdaGT6dFnCDo/bJPiQ+uDScMNG1mqJcWURWxIYJvkC7HQxcWJI/D+1a1guuA==","X-Received":"by 10.159.252.131 with SMTP id bb3mr1140696plb.68.1510826393455; \n\tThu, 16 Nov 2017 01:59:53 -0800 (PST)","From":"Daniel Axtens <dja@axtens.net>","To":"Stephen Finucane <stephen@that.guru>, patchwork@lists.ozlabs.org","Subject":"Re: [PATCH v2 2/9] urls: Use new login/password change CBVs","In-Reply-To":"<20171102102844.18931-3-stephen@that.guru>","References":"<20171102102844.18931-1-stephen@that.guru>\n\t<20171102102844.18931-3-stephen@that.guru>","Date":"Thu, 16 Nov 2017 20:59:49 +1100","Message-ID":"<87d14io86i.fsf@linkitivity.dja.id.au>","MIME-Version":"1.0","X-BeenThere":"patchwork@lists.ozlabs.org","X-Mailman-Version":"2.1.24","Precedence":"list","List-Id":"Patchwork development <patchwork.lists.ozlabs.org>","List-Unsubscribe":"<https://lists.ozlabs.org/options/patchwork>,\n\t<mailto:patchwork-request@lists.ozlabs.org?subject=unsubscribe>","List-Archive":"<http://lists.ozlabs.org/pipermail/patchwork/>","List-Post":"<mailto:patchwork@lists.ozlabs.org>","List-Help":"<mailto:patchwork-request@lists.ozlabs.org?subject=help>","List-Subscribe":"<https://lists.ozlabs.org/listinfo/patchwork>,\n\t<mailto:patchwork-request@lists.ozlabs.org?subject=subscribe>","Content-Type":"text/plain; charset=\"utf-8\"","Content-Transfer-Encoding":"base64","Errors-To":"patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org","Sender":"\"Patchwork\"\n\t<patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org>"}}]