Skip to content

Commit 2a44792

Browse files
committed
Add django-upgrade pre-commit task and fix a couple of issues
1 parent b05899c commit 2a44792

File tree

7 files changed

+25
-34
lines changed

7 files changed

+25
-34
lines changed

.pre-commit-config.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ repos:
88
entry: 'breakpoint\(\)|set_trace'
99
language: pygrep
1010

11+
- repo: https://github.com/adamchainz/django-upgrade
12+
rev: "1.20.0"
13+
hooks:
14+
- id: django-upgrade
15+
args: [--target-version, "2.2"]
16+
1117
- repo: https://github.com/pre-commit/pre-commit-hooks
1218
rev: 'v4.6.0'
1319
hooks:

HISTORY.rst

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ Unreleased
33

44
* Remove unsupported Django code
55
* Added ``__str__()`` definitions for models
6+
* Use path instead of re_path for some URLs
67

78
0.8.6
89
-----

docs/topics/custom.validation.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,6 @@ URL pattern needs to be added to a project's ``URLconf``::
6868

6969
from your_app.forms import CustomPasswordPoliciesForm
7070

71-
urlpatterns = patterns('',
72-
(r'^password/reset/', PasswordResetConfirmView.as_view(form_class=CustomPasswordPoliciesForm)),
73-
)
71+
urlpatterns = [
72+
path("password/reset/", PasswordResetConfirmView.as_view(form_class=CustomPasswordPoliciesForm)),
73+
]

password_policies/admin.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def force_password_change(modeladmin, request, queryset):
1919
)
2020

2121

22+
@admin.register(PasswordHistory)
2223
class PasswordHistoryAdmin(admin.ModelAdmin):
2324
date_hierarchy = "created"
2425
exclude = ("password",)
@@ -34,6 +35,7 @@ def has_add_permission(self, request):
3435
return False
3536

3637

38+
@admin.register(PasswordChangeRequired)
3739
class PasswordChangeRequiredAdmin(admin.ModelAdmin):
3840
date_hierarchy = "created"
3941
list_display = ("id", "user", "created")
@@ -52,7 +54,3 @@ def get_readonly_fields(self, request, obj=None):
5254
return ["user"]
5355
else:
5456
return []
55-
56-
57-
admin.site.register(PasswordHistory, PasswordHistoryAdmin)
58-
admin.site.register(PasswordChangeRequired, PasswordChangeRequiredAdmin)

password_policies/tests/urls.py

+4-16
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,9 @@
1-
try:
2-
from django.conf.urls import include, url
3-
except ImportError:
4-
from django.urls import include
5-
from django.urls import re_path as url
6-
7-
try:
8-
from django.conf.urls import patterns
9-
except ImportError:
10-
patterns = False
1+
from django.urls import include, path
112

123
from password_policies.tests.views import TestHomeView, TestLoggedOutMixinView
134

145
urlpatterns = [
15-
url(r"^password/", include("password_policies.urls")),
16-
url(r"^$", TestHomeView.as_view(), name="home"),
17-
url(r"^fubar/", TestLoggedOutMixinView.as_view(), name="loggedoutmixin"),
6+
path("password/", include("password_policies.urls")),
7+
path("", TestHomeView.as_view(), name="home"),
8+
path("fubar/", TestLoggedOutMixinView.as_view(), name="loggedoutmixin"),
189
]
19-
20-
if patterns:
21-
urlpatterns = patterns("", *urlpatterns) # noqa

password_policies/urls.py

+8-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from django.urls import re_path as url
1+
from django.urls import path, re_path
22

33
from password_policies.views import (
44
PasswordChangeDoneView,
@@ -10,20 +10,18 @@
1010
)
1111

1212
urlpatterns = [
13-
url(
14-
r"^change/done/$", PasswordChangeDoneView.as_view(), name="password_change_done"
15-
),
16-
url(r"^change/$", PasswordChangeFormView.as_view(), name="password_change"),
17-
url(r"^reset/$", PasswordResetFormView.as_view(), name="password_reset"),
18-
url(
19-
r"^reset/complete/$",
13+
path("change/done/", PasswordChangeDoneView.as_view(), name="password_change_done"),
14+
path("change/", PasswordChangeFormView.as_view(), name="password_change"),
15+
path("reset/", PasswordResetFormView.as_view(), name="password_reset"),
16+
path(
17+
"reset/complete/",
2018
PasswordResetCompleteView.as_view(),
2119
name="password_reset_complete",
2220
),
23-
url(
21+
re_path(
2422
r"^reset/confirm/([0-9A-Za-z_\-]+)/([0-9A-Za-z]{1,13})/([0-9A-Za-z-=_]{1,128})/$",
2523
PasswordResetConfirmView.as_view(),
2624
name="password_reset_confirm",
2725
),
28-
url(r"^reset/done/$", PasswordResetDoneView.as_view(), name="password_reset_done"),
26+
path("reset/done/", PasswordResetDoneView.as_view(), name="password_reset_done"),
2927
]

password_policies/views.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ def form_valid(self, form):
261261
"request": self.request,
262262
}
263263
if self.is_admin_site:
264-
opts = dict(opts, domain_override=self.request.META["HTTP_HOST"])
264+
opts = dict(opts, domain_override=self.request.headers["host"])
265265
form.save(**opts)
266266
return super().form_valid(form)
267267

0 commit comments

Comments
 (0)