Skip to content

Commit 20b0164

Browse files
authored
Merge pull request #562 from liangliangyy/dev
django 4.0支持
2 parents 63fa63c + 5e06089 commit 20b0164

File tree

10 files changed

+53
-52
lines changed

10 files changed

+53
-52
lines changed

.github/workflows/django.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
strategy:
2727
max-parallel: 4
2828
matrix:
29-
python-version: [3.7, 3.8, 3.9 ]
29+
python-version: [ 3.8, 3.9 ]
3030

3131
steps:
3232
- name: Start MySQL
@@ -65,7 +65,7 @@ jobs:
6565
strategy:
6666
max-parallel: 4
6767
matrix:
68-
python-version: [3.7, 3.8, 3.9 ]
68+
python-version: [ 3.8, 3.9 ]
6969

7070
steps:
7171
- name: Start MySQL

accounts/urls.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
from django.conf.urls import url
1+
from django.urls import include, re_path
22
from django.urls import path
33

44
from . import views
55
from .forms import LoginForm
66

77
app_name = "accounts"
88

9-
urlpatterns = [url(r'^login/$',
9+
urlpatterns = [re_path(r'^login/$',
1010
views.LoginView.as_view(success_url='/'),
1111
name='login',
1212
kwargs={'authentication_form': LoginForm}),
13-
url(r'^register/$',
13+
re_path(r'^register/$',
1414
views.RegisterView.as_view(success_url="/"),
1515
name='register'),
16-
url(r'^logout/$',
16+
re_path(r'^logout/$',
1717
views.LogoutView.as_view(),
1818
name='logout'),
1919
path(r'account/result.html',
2020
views.account_result,
2121
name='result'),
22-
url(r'^forget_password/$',
22+
re_path(r'^forget_password/$',
2323
views.ForgetPasswordView.as_view(),
2424
name='forget_password'),
25-
url(r'^forget_password_code/$',
25+
re_path(r'^forget_password_code/$',
2626
views.ForgetPasswordEmailCode.as_view(),
2727
name='forget_password_code'),
2828
]

accounts/views.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from django.shortcuts import render
1515
from django.urls import reverse
1616
from django.utils.decorators import method_decorator
17-
from django.utils.http import is_safe_url
17+
from django.utils.http import url_has_allowed_host_and_scheme
1818
from django.views import View
1919
from django.views.decorators.cache import never_cache
2020
from django.views.decorators.csrf import csrf_protect
@@ -135,7 +135,7 @@ def form_valid(self, form):
135135
def get_success_url(self):
136136

137137
redirect_to = self.request.POST.get(self.redirect_field_name)
138-
if not is_safe_url(
138+
if not url_has_allowed_host_and_scheme(
139139
url=redirect_to, allowed_hosts=[
140140
self.request.get_host()]):
141141
redirect_to = self.success_url

blog/admin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from django.contrib.auth import get_user_model
44
from django.urls import reverse
55
from django.utils.html import format_html
6-
from django.utils.translation import ugettext_lazy as _
6+
from django.utils.translation import gettext_lazy as _
77

88
# Register your models here.
99
from .models import Article

djangoblog/blog_signals.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818

1919
logger = logging.getLogger(__name__)
2020

21-
oauth_user_login_signal = django.dispatch.Signal(providing_args=['id'])
21+
oauth_user_login_signal = django.dispatch.Signal(['id'])
2222
send_email_signal = django.dispatch.Signal(
23-
providing_args=['emailto', 'title', 'content'])
23+
['emailto', 'title', 'content'])
2424

2525

2626
@receiver(send_email_signal)

djangoblog/elasticsearch_backend.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from django.utils.encoding import force_text
1+
from django.utils.encoding import force_str
22
from elasticsearch_dsl import Q
33
from haystack.backends import BaseEngine, BaseSearchBackend, BaseSearchQuery, log_query
44
from haystack.models import SearchResult
@@ -98,9 +98,9 @@ def search(self, query_string, **kwargs):
9898
class ElasticSearchQuery(BaseSearchQuery):
9999
def _convert_datetime(self, date):
100100
if hasattr(date, 'hour'):
101-
return force_text(date.strftime('%Y%m%d%H%M%S'))
101+
return force_str(date.strftime('%Y%m%d%H%M%S'))
102102
else:
103-
return force_text(date.strftime('%Y%m%d000000'))
103+
return force_str(date.strftime('%Y%m%d000000'))
104104

105105
def clean(self, query_fragment):
106106
"""

djangoblog/logentryadmin.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
from django.contrib.admin.models import LogEntry, ADDITION, CHANGE, DELETION
33
from django.contrib.contenttypes.models import ContentType
44
from django.urls import reverse, NoReverseMatch
5-
from django.utils.encoding import force_text
5+
from django.utils.encoding import force_str
66
from django.utils.html import escape
77
from django.utils.safestring import mark_safe
8-
from django.utils.translation import pgettext_lazy, ugettext_lazy as _
8+
from django.utils.translation import pgettext_lazy, gettext_lazy as _
99

1010
action_names = {
1111
ADDITION: pgettext_lazy('logentry_admin:action_type', 'Addition'),
@@ -96,7 +96,7 @@ def object_link(self, obj):
9696

9797
def user_link(self, obj):
9898
content_type = ContentType.objects.get_for_model(type(obj.user))
99-
user_link = escape(force_text(obj.user))
99+
user_link = escape(force_str(obj.user))
100100
try:
101101
# try returning an actual link instead of object repr string
102102
url = reverse(

djangoblog/urls.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
1515
"""
1616
from django.conf import settings
17-
from django.conf.urls import url
17+
from django.urls import include, re_path
1818
from django.conf.urls.static import static
1919
from django.contrib.sitemaps.views import sitemap
2020
from django.urls import include
@@ -36,19 +36,19 @@
3636
handler500 = 'blog.views.server_error_view'
3737
handle403 = 'blog.views.permission_denied_view'
3838
urlpatterns = [
39-
url(r'^admin/', admin_site.urls),
40-
url(r'', include('blog.urls', namespace='blog')),
41-
url(r'mdeditor/', include('mdeditor.urls')),
42-
url(r'', include('comments.urls', namespace='comment')),
43-
url(r'', include('accounts.urls', namespace='account')),
44-
url(r'', include('oauth.urls', namespace='oauth')),
45-
url(r'^sitemap\.xml$', sitemap, {'sitemaps': sitemaps},
39+
re_path(r'^admin/', admin_site.urls),
40+
re_path(r'', include('blog.urls', namespace='blog')),
41+
re_path(r'mdeditor/', include('mdeditor.urls')),
42+
re_path(r'', include('comments.urls', namespace='comment')),
43+
re_path(r'', include('accounts.urls', namespace='account')),
44+
re_path(r'', include('oauth.urls', namespace='oauth')),
45+
re_path(r'^sitemap\.xml$', sitemap, {'sitemaps': sitemaps},
4646
name='django.contrib.sitemaps.views.sitemap'),
47-
url(r'^feed/$', DjangoBlogFeed()),
48-
url(r'^rss/$', DjangoBlogFeed()),
49-
url(r'^search', include('haystack.urls'), name='search'),
50-
url(r'', include('servermanager.urls', namespace='servermanager')),
51-
url(r'', include('owntracks.urls', namespace='owntracks'))
47+
re_path(r'^feed/$', DjangoBlogFeed()),
48+
re_path(r'^rss/$', DjangoBlogFeed()),
49+
re_path(r'^search', include('haystack.urls'), name='search'),
50+
re_path(r'', include('servermanager.urls', namespace='servermanager')),
51+
re_path(r'', include('owntracks.urls', namespace='owntracks'))
5252
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
5353
if settings.DEBUG:
5454
urlpatterns += static(settings.MEDIA_URL,

djangoblog/whoosh_cn_backend.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from django.conf import settings
1414
from django.core.exceptions import ImproperlyConfigured
1515
from django.utils.datetime_safe import datetime
16-
from django.utils.encoding import force_text
16+
from django.utils.encoding import force_str
1717
from haystack.backends import BaseEngine, BaseSearchBackend, BaseSearchQuery, EmptyResults, log_query
1818
from haystack.constants import DJANGO_CT, DJANGO_ID, ID
1919
from haystack.exceptions import MissingDependency, SearchBackendError, SkipDocument
@@ -376,7 +376,7 @@ def search(
376376
'hits': 0,
377377
}
378378

379-
query_string = force_text(query_string)
379+
query_string = force_str(query_string)
380380

381381
# A one-character query (non-wildcard) gets nabbed by a stopwords
382382
# filter and should yield zero results.
@@ -467,7 +467,7 @@ def search(
467467

468468
for nq in narrow_queries:
469469
recent_narrowed_results = narrow_searcher.search(
470-
self.parser.parse(force_text(nq)), limit=None)
470+
self.parser.parse(force_str(nq)), limit=None)
471471

472472
if len(recent_narrowed_results) <= 0:
473473
return {
@@ -614,7 +614,7 @@ def more_like_this(
614614

615615
for nq in narrow_queries:
616616
recent_narrowed_results = narrow_searcher.search(
617-
self.parser.parse(force_text(nq)), limit=None)
617+
self.parser.parse(force_str(nq)), limit=None)
618618

619619
if len(recent_narrowed_results) <= 0:
620620
return {
@@ -771,7 +771,7 @@ def create_spelling_suggestion(self, query_string):
771771
spelling_suggestion = None
772772
reader = self.index.reader()
773773
corrector = reader.corrector(self.content_field_name)
774-
cleaned_query = force_text(query_string)
774+
cleaned_query = force_str(query_string)
775775

776776
if not query_string:
777777
return spelling_suggestion
@@ -811,12 +811,12 @@ def _from_python(self, value):
811811
else:
812812
value = 'false'
813813
elif isinstance(value, (list, tuple)):
814-
value = u','.join([force_text(v) for v in value])
814+
value = u','.join([force_str(v) for v in value])
815815
elif isinstance(value, (six.integer_types, float)):
816816
# Leave it alone.
817817
pass
818818
else:
819-
value = force_text(value)
819+
value = force_str(value)
820820
return value
821821

822822
def _to_python(self, value):
@@ -873,9 +873,9 @@ def _to_python(self, value):
873873
class WhooshSearchQuery(BaseSearchQuery):
874874
def _convert_datetime(self, date):
875875
if hasattr(date, 'hour'):
876-
return force_text(date.strftime('%Y%m%d%H%M%S'))
876+
return force_str(date.strftime('%Y%m%d%H%M%S'))
877877
else:
878-
return force_text(date.strftime('%Y%m%d000000'))
878+
return force_str(date.strftime('%Y%m%d000000'))
879879

880880
def clean(self, query_fragment):
881881
"""

requirements.txt

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
1-
coverage==6.2
1+
coverage==6.3.2
22
bleach==4.1.0
3-
Django==3.2.12
3+
Django==4.0.3
44
django-compressor==3.1
5-
django-haystack==3.1.1
5+
django-haystack==3.2.dev0
66
django-ipware==4.0.2
7-
django-mdeditor==0.1.18
8-
django-uuslug==1.2.0
7+
django-mdeditor==0.1.20
8+
django-uuslug==2.0.0
99
elasticsearch==7.16.1
1010
elasticsearch-dsl==7.4.0
1111
gevent==21.12.0
1212
jieba==0.42.1
13-
jsonpickle==2.0.0
13+
jsonpickle==2.1.0
1414
Markdown==3.3.6
1515
mysqlclient==2.1.0
1616
Pillow==9.0.1
17-
Pygments==2.10.0
17+
Pygments==2.11.2
1818
python-logstash==0.4.6
1919
python-memcached==1.59
20-
python-slugify==5.0.2
21-
pytz==2021.3
20+
python-slugify==6.1.1
21+
pytz==2022.1
2222
raven==6.10.0
23-
requests==2.26.0
24-
urllib3==1.26.7
23+
requests==2.27.1
24+
urllib3==1.26.9
2525
WeRoBot==1.13.1
2626
Whoosh==2.7.4
2727
user-agents==2.2.0
28+
redis==4.1.4

0 commit comments

Comments
 (0)