fix: fixed django4 warnings (#29644)

This commit is contained in:
Mohammad Ahtasham ul Hassan
2022-03-07 15:50:17 +05:00
committed by GitHub
parent 533b971d83
commit 68e0885ca8
11 changed files with 134 additions and 181 deletions

View File

@@ -4,7 +4,7 @@ Defines the URL routes for this app.
from django.conf import settings
from django.conf.urls import include, url
from django.urls import include, path, re_path
from rest_framework import routers
from ..profile_images.views import ProfileImageView
@@ -95,151 +95,121 @@ USER_API_ROUTER.register(r'users', user_api_views.UserViewSet)
USER_API_ROUTER.register(r'user_prefs', user_api_views.UserPreferenceViewSet)
urlpatterns = [
url(
r'^v1/me$',
ME,
name='own_username_api'
),
url(
r'^v1/accounts$',
ACCOUNT_LIST,
name='accounts_detail_api'
),
url(
r'^v1/accounts/search_emails$',
ACCOUNT_SEARCH_EMAILS,
name='accounts_search_emails_api'
),
url(
path('v1/me', ME,
name='own_username_api'
),
path('v1/accounts', ACCOUNT_LIST,
name='accounts_detail_api'
),
path('v1/accounts/search_emails', ACCOUNT_SEARCH_EMAILS,
name='accounts_search_emails_api'
),
re_path(
fr'^v1/accounts/{settings.USERNAME_PATTERN}$',
ACCOUNT_DETAIL,
name='accounts_api'
),
url(
re_path(
fr'^v1/accounts/{settings.USERNAME_PATTERN}/image$',
ProfileImageView.as_view(),
name='accounts_profile_image_api'
),
url(
re_path(
fr'^v1/accounts/{settings.USERNAME_PATTERN}/deactivate/$',
AccountDeactivationView.as_view(),
name='accounts_deactivation'
),
url(
r'^v1/accounts/deactivate_logout/$',
DeactivateLogoutView.as_view(),
path(
'v1/accounts/deactivate_logout/', DeactivateLogoutView.as_view(),
name='deactivate_logout'
),
url(
r'^v1/accounts/name_change/$',
REQUEST_NAME_CHANGE,
path(
'v1/accounts/name_change/', REQUEST_NAME_CHANGE,
name='request_name_change'
),
url(
re_path(
fr'^v1/accounts/name_change/{settings.USERNAME_PATTERN}/confirm/$',
CONFIRM_NAME_CHANGE,
name='confirm_name_change'
),
url(
re_path(
fr'^v1/accounts/{settings.USERNAME_PATTERN}/verification_status/$',
IDVerificationStatusView.as_view(),
name='verification_status'
),
url(
re_path(
fr'^v1/accounts/{settings.USERNAME_PATTERN}/verifications/$',
IDVerificationStatusDetailsView.as_view(),
name='verification_details'
),
url(
re_path(
r'^v1/accounts/verifications/(?P<attempt_id>[0-9]+)/$',
IDVerificationSupportView.as_view(),
name='verification_for_support'
),
url(
re_path(
fr'^v1/accounts/{settings.USERNAME_PATTERN}/retirement_status/$',
RETIREMENT_RETRIEVE,
name='accounts_retirement_retrieve'
),
url(
r'^v1/accounts/retirement_partner_report/$',
PARTNER_REPORT,
name='accounts_retirement_partner_report'
),
url(
r'^v1/accounts/retirement_partner_report_cleanup/$',
PARTNER_REPORT_CLEANUP,
name='accounts_retirement_partner_report_cleanup'
),
url(
r'^v1/accounts/retirement_queue/$',
RETIREMENT_QUEUE,
name='accounts_retirement_queue'
),
url(
r'^v1/accounts/retirement_cleanup/$',
RETIREMENT_CLEANUP,
name='accounts_retirement_cleanup'
),
url(
r'^v1/accounts/retirements_by_status_and_date/$',
RETIREMENT_LIST_BY_STATUS_AND_DATE,
name='accounts_retirements_by_status_and_date'
),
url(
r'^v1/accounts/retire/$',
RETIREMENT_POST,
name='accounts_retire'
),
url(
r'^v1/accounts/retire_misc/$',
RETIREMENT_LMS_POST,
name='accounts_retire_misc'
),
url(
r'^v1/accounts/update_retirement_status/$',
RETIREMENT_UPDATE,
name='accounts_retirement_update'
),
url(
r'^v1/accounts/replace_usernames/$',
UsernameReplacementView.as_view(),
name='username_replacement'
),
url(
path('v1/accounts/retirement_partner_report/', PARTNER_REPORT,
name='accounts_retirement_partner_report'
),
path('v1/accounts/retirement_partner_report_cleanup/', PARTNER_REPORT_CLEANUP,
name='accounts_retirement_partner_report_cleanup'
),
path('v1/accounts/retirement_queue/', RETIREMENT_QUEUE,
name='accounts_retirement_queue'
),
path('v1/accounts/retirement_cleanup/', RETIREMENT_CLEANUP,
name='accounts_retirement_cleanup'
),
path('v1/accounts/retirements_by_status_and_date/', RETIREMENT_LIST_BY_STATUS_AND_DATE,
name='accounts_retirements_by_status_and_date'
),
path('v1/accounts/retire/', RETIREMENT_POST,
name='accounts_retire'
),
path('v1/accounts/retire_misc/', RETIREMENT_LMS_POST,
name='accounts_retire_misc'
),
path('v1/accounts/update_retirement_status/', RETIREMENT_UPDATE,
name='accounts_retirement_update'
),
path('v1/accounts/replace_usernames/', UsernameReplacementView.as_view(),
name='username_replacement'
),
re_path(
fr'^v1/preferences/{settings.USERNAME_PATTERN}$',
PreferencesView.as_view(),
name='preferences_api'
),
url(
re_path(
fr'^v1/preferences/{settings.USERNAME_PATTERN}/(?P<preference_key>[a-zA-Z0-9_]+)$',
PreferencesDetailView.as_view(),
name='preferences_detail_api'
),
# Moved from user_api/legacy_urls.py
url(r'^v1/', include(USER_API_ROUTER.urls)),
path('v1/', include(USER_API_ROUTER.urls)),
# Moved from user_api/legacy_urls.py
url(
re_path(
fr'^v1/preferences/(?P<pref_key>{UserPreference.KEY_REGEX})/users/$',
user_api_views.PreferenceUsersListView.as_view()
),
# Moved from user_api/legacy_urls.py
url(
re_path(
r'^v1/forum_roles/(?P<name>[a-zA-Z]+)/users/$',
user_api_views.ForumRoleUsersListView.as_view()
),
# Moved from user_api/legacy_urls.py
url(
r'^v1/preferences/email_opt_in/$',
user_api_views.UpdateEmailOptInPreference.as_view(),
name="preferences_email_opt_in"
),
path('v1/preferences/email_opt_in/', user_api_views.UpdateEmailOptInPreference.as_view(),
name="preferences_email_opt_in"
),
# Moved from user_api/legacy_urls.py
url(
r'^v1/preferences/time_zones/$',
user_api_views.CountryTimeZoneListView.as_view(),
),
path('v1/preferences/time_zones/', user_api_views.CountryTimeZoneListView.as_view(),
),
]

View File

@@ -1,19 +1,15 @@
"""
Authn API urls
"""
from django.conf.urls import url
from django.urls import path
from openedx.core.djangoapps.user_authn.api.views import MFEContextView, SendAccountActivationEmail
from openedx.core.djangoapps.user_authn.api.optional_fields import OptionalFieldsView
urlpatterns = [
url(r'^third_party_auth_context$', MFEContextView.as_view(), name='third_party_auth_context'),
url(r'^mfe_context$', MFEContextView.as_view(), name='mfe_context'),
url(
r'^send_account_activation_email$',
SendAccountActivationEmail.as_view(),
name='send_account_activation_email'
),
url(r'^optional_fields$', OptionalFieldsView.as_view(), name='optional_fields'),
path('third_party_auth_context', MFEContextView.as_view(), name='third_party_auth_context'),
path('mfe_context', MFEContextView.as_view(), name='mfe_context'),
path('send_account_activation_email', SendAccountActivationEmail.as_view(),
name='send_account_activation_email'
),
path('optional_fields', OptionalFieldsView.as_view(), name='optional_fields'),
]

View File

@@ -1,23 +1,23 @@
""" URLs for User Authentication """
from django.conf.urls import include, url
from django.urls import include, path
from .views import login, login_form
urlpatterns = [
# TODO move contents of urls_common here once CMS no longer has its own login
url(r'', include('openedx.core.djangoapps.user_authn.urls_common')),
url(r'^api/', include('openedx.core.djangoapps.user_authn.api.urls')),
url(r'^account/finish_auth$', login.finish_auth, name='finish_auth'),
path('', include('openedx.core.djangoapps.user_authn.urls_common')),
path('api/', include('openedx.core.djangoapps.user_authn.api.urls')),
path('account/finish_auth', login.finish_auth, name='finish_auth'),
]
# Backwards compatibility with old URL structure, but serve the new views
urlpatterns += [
url(r'^login$', login_form.login_and_registration_form,
{'initial_mode': 'login'}, name='signin_user'),
url(r'^register$', login_form.login_and_registration_form,
{'initial_mode': 'register'}, name='register_user'),
url(r'^password_assistance', login_form.login_and_registration_form,
{'initial_mode': 'reset'}, name='password_assistance'),
path('login', login_form.login_and_registration_form,
{'initial_mode': 'login'}, name='signin_user'),
path('register', login_form.login_and_registration_form,
{'initial_mode': 'register'}, name='register_user'),
path('password_assistance', login_form.login_and_registration_form,
{'initial_mode': 'reset'}, name='password_assistance'),
]

View File

@@ -12,95 +12,85 @@ which leads to inconsistent prefixing.
from django.conf import settings
from django.conf.urls import url
from django.contrib.auth.views import PasswordResetCompleteView
from django.urls import path, re_path
from .views import auto_auth, login, logout, password_reset, register
from .views.password_reset import PasswordResetConfirmWrapper
urlpatterns = [
# Registration
url(r'^create_account$', register.RegistrationView.as_view(), name='create_account'),
path('create_account', register.RegistrationView.as_view(), name='create_account'),
# Moved from user_api/legacy_urls.py
url(
r'^api/user/v1/account/registration/$',
register.RegistrationView.as_view(),
name="user_api_registration"
),
path('api/user/v1/account/registration/', register.RegistrationView.as_view(),
name="user_api_registration"
),
# `user_api` prefix is preserved for backwards compatibility.
url(r'^user_api/v1/account/registration/$', register.RegistrationView.as_view(),
name="user_api_registration_legacy"),
path('user_api/v1/account/registration/', register.RegistrationView.as_view(),
name="user_api_registration_legacy"),
# V2 is created to avoid backward compatibility issue with confirm_email
url(
r'^api/user/v2/account/registration/$',
register.RegistrationView.as_view(),
name="user_api_registration_v2"
),
path('api/user/v2/account/registration/', register.RegistrationView.as_view(),
name="user_api_registration_v2"
),
# legacy url
url(r'^user_api/v2/account/registration/$', register.RegistrationView.as_view(),
name="user_api_registration_v2_legacy"),
path('user_api/v2/account/registration/', register.RegistrationView.as_view(),
name="user_api_registration_v2_legacy"),
# Moved from user_api/urls.py
# `api/user` prefix is preserved for backwards compatibility.
url(
r'^api/user/v1/validation/registration$',
register.RegistrationValidationView.as_view(),
name='registration_validation'
),
path('api/user/v1/validation/registration', register.RegistrationValidationView.as_view(),
name='registration_validation'
),
url(r'^login_ajax$', login.login_user, name="login_api"),
path('login_ajax', login.login_user, name="login_api"),
# Moved from user_api/legacy_urls.py
url(
re_path(
r'^api/user/(?P<api_version>v(1|2))/account/login_session/$',
login.LoginSessionView.as_view(),
name="user_api_login_session"
),
# `user_api` prefix is preserved for backwards compatibility.
url(r'^user_api/(?P<api_version>v(1|2))/account/login_session/$', login.LoginSessionView.as_view(),
name="user_api_login_session_legacy"),
re_path(r'^user_api/(?P<api_version>v(1|2))/account/login_session/$', login.LoginSessionView.as_view(),
name="user_api_login_session_legacy"),
# Login Refresh of JWT Cookies
url(r'^login_refresh$', login.login_refresh, name="login_refresh"),
path('login_refresh', login.login_refresh, name="login_refresh"),
# WARNING: This is similar to auth_backends ^logout/$ (which has a
# trailing slash); LMS uses this view, but Studio links to the
# auth_backends logout view.
url(r'^logout$', logout.LogoutView.as_view(), name='logout'),
path('logout', logout.LogoutView.as_view(), name='logout'),
# Moved from user_api/legacy_urls.py
url(
r'^api/user/v1/account/password_reset/$',
password_reset.PasswordResetView.as_view(),
name="user_api_password_reset"
),
path('api/user/v1/account/password_reset/', password_reset.PasswordResetView.as_view(),
name="user_api_password_reset"
),
# legacy url
url(r'^user_api/v1/account/password_reset/$', password_reset.PasswordResetView.as_view(),
name="user_api_password_reset_legacy"),
path('user_api/v1/account/password_reset/', password_reset.PasswordResetView.as_view(),
name="user_api_password_reset_legacy"),
# Password reset api views.
url(r'^password_reset/$', password_reset.password_reset, name='password_reset'),
url(
path('password_reset/', password_reset.password_reset, name='password_reset'),
re_path(
r'^password_reset_confirm/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/$',
PasswordResetConfirmWrapper.as_view(),
name='password_reset_confirm',
),
url(r'^account/password$', password_reset.password_change_request_handler, name='password_change_request'),
path('account/password', password_reset.password_change_request_handler, name='password_change_request'),
# authn MFE flow
url(
r'^api/user/v1/account/password_reset/token/validate/$',
password_reset.PasswordResetTokenValidation.as_view(),
name="user_api_password_reset_token_validate"
),
path('api/user/v1/account/password_reset/token/validate/', password_reset.PasswordResetTokenValidation.as_view(),
name="user_api_password_reset_token_validate"
),
# legacy url
url(r'^user_api/v1/account/password_reset/token/validate/$', password_reset.PasswordResetTokenValidation.as_view(),
name="user_api_password_reset_token_validate_legacy"),
path('user_api/v1/account/password_reset/token/validate/', password_reset.PasswordResetTokenValidation.as_view(),
name="user_api_password_reset_token_validate_legacy"),
# authn MFE reset flow
url(
re_path(
r'^password/reset/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/$',
password_reset.LogistrationPasswordResetView.as_view(),
name='logistration_password_reset',
@@ -109,15 +99,13 @@ urlpatterns = [
# password reset django views (see above for password reset views)
urlpatterns += [
url(
r'^password_reset_complete/$',
PasswordResetCompleteView.as_view(),
name='password_reset_complete',
),
path('password_reset_complete/', PasswordResetCompleteView.as_view(),
name='password_reset_complete',
),
]
# enable automatic login
if settings.FEATURES.get('AUTOMATIC_AUTH_FOR_TESTING'):
urlpatterns += [
url(r'^auto_auth$', auto_auth.auto_auth),
path('auto_auth', auto_auth.auto_auth),
]

View File

@@ -1,8 +1,7 @@
""" URL definitions for waffle utils. """
from django.conf.urls import url
from django.urls import path
from openedx.core.djangoapps.waffle_utils.views import ToggleStateView
urlpatterns = [
url(r'^v0/state/', ToggleStateView.as_view(), name="toggle_state"),
path('v0/state/', ToggleStateView.as_view(), name="toggle_state"),
]

View File

@@ -1,8 +1,7 @@
"""
URL configuration for the new XBlock API
"""
from django.conf.urls import include, url
from django.urls import include, path, re_path
from . import views
# Note that the exact same API URLs are used in Studio and the LMS, but the API
@@ -12,16 +11,16 @@ from . import views
app_name = 'openedx.core.djangoapps.xblock.rest_api'
urlpatterns = [
url(r'^api/xblock/v2/', include([
url(r'^xblocks/(?P<usage_key_str>[^/]+)/', include([
path('api/xblock/v2/', include([
path('xblocks/<str:usage_key_str>/', include([
# get metadata about an XBlock:
url(r'^$', views.block_metadata),
path('', views.block_metadata),
# render one of this XBlock's views (e.g. student_view)
url(r'^view/(?P<view_name>[\w\-]+)/$', views.render_block_view),
re_path(r'^view/(?P<view_name>[\w\-]+)/$', views.render_block_view),
# get the URL needed to call this XBlock's handlers
url(r'^handler_url/(?P<handler_name>[\w\-]+)/$', views.get_handler_url),
re_path(r'^handler_url/(?P<handler_name>[\w\-]+)/$', views.get_handler_url),
# call one of this block's handlers
url(
re_path(
r'^handler/(?P<user_id>\w+)-(?P<secure_token>\w+)/(?P<handler_name>[\w\-]+)/(?P<suffix>.+)?$',
views.xblock_handler,
name='xblock_handler',

View File

@@ -2,13 +2,11 @@
Map urls to the relevant view handlers
"""
from django.conf.urls import url
from django.urls import path
from openedx.core.djangoapps.zendesk_proxy.v0.views import ZendeskPassthroughView as v0_view
from openedx.core.djangoapps.zendesk_proxy.v1.views import ZendeskPassthroughView as v1_view
urlpatterns = [
url(r'^v0$', v0_view.as_view(), name='zendesk_proxy_v0'),
url(r'^v1$', v1_view.as_view(), name='zendesk_proxy_v1'),
path('v0', v0_view.as_view(), name='zendesk_proxy_v0'),
path('v1', v1_view.as_view(), name='zendesk_proxy_v1'),
]

View File

@@ -24,7 +24,7 @@ def HTML(html): # pylint: disable=invalid-name
<%page expression_filter="h"/>
<%!
from django.utils.translation import ugettext as _
from django.utils.translation import gettext as _
from openedx.core.djangolib.markup import HTML, Text
%>

View File

@@ -53,7 +53,7 @@ class FormatHtmlTest(unittest.TestCase):
template = Template(
"""
<%!
from django.utils.translation import ugettext as _
from django.utils.translation import gettext as _
from openedx.core.djangolib.markup import HTML, Text
%>

View File

@@ -33,6 +33,7 @@ class DeveloperErrorResponseException(Exception):
it does not need to be recreated when returning a response.
Intended to be used with and by DeveloperErrorViewMixin.
"""
def __init__(self, response):
super().__init__()
self.response = response
@@ -174,7 +175,7 @@ def build_api_error(message, **kwargs):
Args:
message (string): The string to use for developer and user messages.
The user message will be translated, but for this to work message
must have already been scraped. ugettext_noop is useful for this.
must have already been scraped. gettext_noop is useful for this.
**kwargs: format parameters for message
"""
return {
@@ -188,6 +189,7 @@ class RetrievePatchAPIView(RetrieveModelMixin, UpdateModelMixin, GenericAPIView)
Like DRF's RetrieveUpdateAPIView, but without PUT and with automatic validation errors in the edX format.
"""
def get(self, request, *args, **kwargs):
"""Retrieves the specified resource using the RetrieveModelMixin."""
return self.retrieve(request, *args, **kwargs)
@@ -245,6 +247,7 @@ class LazySequence(Sequence):
It is immutable, and accepts an estimated length in order to support __len__
without exhausting the underlying sequence
"""
def __init__(self, iterable, est_len=None):
self.iterable = iterable
self.est_len = est_len

View File

@@ -6,7 +6,7 @@ from xblock.core import XBlockMixin
from xblock.fields import Scope, String
# Make '_' a no-op so we can scrape strings. Using lambda instead of
# `django.utils.translation.ugettext_noop` because Django cannot be imported in this file
# `django.utils.translation.gettext_noop` because Django cannot be imported in this file
_ = lambda text: text