Address RemovedInDjango40Warning (2)

django.utils.translation.ugettext(), ugettext_lazy(), ugettext_noop(),
ungettext(), and ungettext_lazy() are deprecated in favor of the
functions that they’re aliases for: django.utils.translation.gettext(),
gettext_lazy(), gettext_noop(), ngettext(), and ngettext_lazy().

On top of that django.conf.urls.url() is deprecated in favor of
django.urls.re_path()

Since Horizon is using Django>4.0, it's highly important to cover these
issues for upcoming release.

https: //docs.djangoproject.com/en/4.0/releases/3.0/#id3
Change-Id: Ibefe848cf73a31608ce5e71f4847b741ec16f8ad
This commit is contained in:
Dmitriy Rabotyagov 2024-03-08 17:27:31 +01:00
parent 02dd3d7363
commit 2bea2114fb
45 changed files with 98 additions and 99 deletions

View File

@ -19,7 +19,7 @@ import requests
from urllib.parse import urljoin
from django.conf import settings
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from horizon import exceptions
from horizon.utils import functions as utils

View File

@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
import horizon

View File

@ -13,7 +13,7 @@
# under the License.
from django.forms import ValidationError
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from horizon import forms
from horizon import messages

View File

@ -12,7 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
import horizon

View File

@ -12,11 +12,11 @@
# License for the specific language governing permissions and limitations
# under the License.
from django.conf.urls import url
from django.urls import re_path
from adjutant_ui.content.email import views
urlpatterns = [
url(r'^$', views.EmailView.as_view(), name='index')
re_path(r'^$', views.EmailView.as_view(), name='index')
]

View File

@ -13,7 +13,7 @@
# under the License.
from django.urls import reverse_lazy
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from horizon import forms

View File

@ -15,7 +15,7 @@
from django.conf import settings
from django import forms
from django import http
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from horizon import forms as hforms
from horizon.utils import functions as utils

View File

@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
import horizon

View File

@ -12,12 +12,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from django.conf.urls import url
from django.urls import re_path
from adjutant_ui.content.forgot_password import views
# NOTE(adriant): These urls are registered in the project_users urls.py file.
urlpatterns = [
url(r'^$', views.ForgotPasswordView.as_view(), name='forgot_index'),
url(r'^sent/?$', views.password_sent_view, name='forgot_sent'),
re_path(r'^$', views.ForgotPasswordView.as_view(), name='forgot_index'),
re_path(r'^sent/?$', views.password_sent_view, name='forgot_sent'),
]

View File

@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
import horizon

View File

@ -13,8 +13,8 @@
# limitations under the License.
from django.urls import reverse
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ungettext_lazy
from django.utils.translation import gettext_lazy as _
from django.utils.translation import ngettext_lazy
from horizon import exceptions
from horizon import tables
@ -28,7 +28,7 @@ class AcknowlegeNotifcation(tables.BatchAction):
@staticmethod
def action_present(count):
return ungettext_lazy(
return ngettext_lazy(
u"Acknowlege Notification",
u"Acknowlege Notifications",
count
@ -36,7 +36,7 @@ class AcknowlegeNotifcation(tables.BatchAction):
@staticmethod
def action_past(count):
return ungettext_lazy(
return ngettext_lazy(
u"Acknowleged Notification",
u"Acknowleged Notifications",
count

View File

@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from horizon import exceptions
from horizon import tabs

View File

@ -13,13 +13,13 @@
# limitations under the License.
from django.conf.urls import url
from django.urls import re_path
from adjutant_ui.content.notifications import views
urlpatterns = [
url(r'^$', views.IndexView.as_view(), name='index'),
url(r'^(?P<notif_id>[^/]+)/$',
views.NotificationDetailView.as_view(), name='detail'),
re_path(r'^$', views.IndexView.as_view(), name='index'),
re_path(r'^(?P<notif_id>[^/]+)/$',
views.NotificationDetailView.as_view(), name='detail'),
]

View File

@ -13,7 +13,7 @@
# limitations under the License.
from django.urls import reverse
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from horizon import exceptions
from horizon import tabs

View File

@ -14,7 +14,7 @@
from django.conf import settings
from django.urls import reverse
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from horizon import exceptions
from horizon import forms

View File

@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
import horizon

View File

@ -14,8 +14,8 @@
from collections import defaultdict
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ungettext_lazy
from django.utils.translation import gettext_lazy as _
from django.utils.translation import ngettext_lazy
from horizon import exceptions
from horizon import tables
@ -32,7 +32,7 @@ class InviteUser(tables.LinkAction):
@staticmethod
def action_past(count):
return ungettext_lazy(
return ngettext_lazy(
u"Invited User",
u"Invited Users",
count
@ -44,7 +44,7 @@ class ResendInvitation(tables.BatchAction):
@staticmethod
def action_present(count):
return ungettext_lazy(
return ngettext_lazy(
u"Resend Invitation",
u"Resend Invitations",
count
@ -52,7 +52,7 @@ class ResendInvitation(tables.BatchAction):
@staticmethod
def action_past(count):
return ungettext_lazy(
return ngettext_lazy(
u"Invitation re-sent",
u"Invitations re-sent",
count
@ -85,7 +85,7 @@ class RevokeUser(tables.DeleteAction):
@staticmethod
def action_present(count):
return ungettext_lazy(
return ngettext_lazy(
u"Revoke User",
u"Revoke Users",
count
@ -93,7 +93,7 @@ class RevokeUser(tables.DeleteAction):
@staticmethod
def action_past(count):
return ungettext_lazy(
return ngettext_lazy(
u"Revoked User",
u"Revoked Users",
count

View File

@ -12,15 +12,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from django.conf.urls import url
from django.urls import re_path
from adjutant_ui.content.project_users import views
urlpatterns = [
url(r'^invite/$', views.InviteUserView.as_view(), name='invite'),
url(r'^(?P<user_id>[^/]+)/update/$',
views.UpdateUserView.as_view(),
name='update'),
url(r'^$', views.UsersView.as_view(), name='index')
re_path(r'^invite/$', views.InviteUserView.as_view(), name='invite'),
re_path(r'^(?P<user_id>[^/]+)/update/$',
views.UpdateUserView.as_view(),
name='update'),
re_path(r'^$', views.UsersView.as_view(), name='index')
]

View File

@ -14,7 +14,7 @@
from django.urls import reverse
from django.urls import reverse_lazy
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from horizon import exceptions
from horizon import forms

View File

@ -15,7 +15,7 @@
import logging
from django.urls import reverse # noqa
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from horizon import exceptions
from horizon import forms

View File

@ -12,7 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
import horizon

View File

@ -14,8 +14,8 @@
import json
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ungettext_lazy
from django.utils.translation import gettext_lazy as _
from django.utils.translation import ngettext_lazy
from horizon import exceptions
from horizon import tables
@ -61,7 +61,7 @@ class CancelQuotaTask(tables.DeleteAction):
@staticmethod
def action_present(count):
return ungettext_lazy(
return ngettext_lazy(
u"Cancel Quota Update",
u"Cancel Quota Updates",
count
@ -69,7 +69,7 @@ class CancelQuotaTask(tables.DeleteAction):
@staticmethod
def action_past(count):
return ungettext_lazy(
return ngettext_lazy(
u"Cancelled Quota Update",
u"Cancelled Quota Updates",
count

View File

@ -12,17 +12,17 @@
# License for the specific language governing permissions and limitations
# under the License.
from django.conf.urls import url
from django.urls import re_path
from adjutant_ui.content.quota import views
urlpatterns = [
url(r'^$', views.IndexView.as_view(), name='index'),
url(r'^region/(?P<region>[^/]+)$', views.RegionDetailView.as_view(),
name='region_detail'),
url(r'^(?P<region>[^/]+)/update$',
views.RegionUpdateView.as_view(), name='update'),
url(r'^size/(?P<size>[^/]+)$', views.QuotaSizeView.as_view(),
name='size_detail'),
re_path(r'^$', views.IndexView.as_view(), name='index'),
re_path(r'^region/(?P<region>[^/]+)$', views.RegionDetailView.as_view(),
name='region_detail'),
re_path(r'^(?P<region>[^/]+)/update$',
views.RegionUpdateView.as_view(), name='update'),
re_path(r'^size/(?P<size>[^/]+)$', views.QuotaSizeView.as_view(),
name='size_detail'),
]

View File

@ -14,7 +14,7 @@
from django.urls import reverse
from django.urls import reverse_lazy
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from horizon import exceptions
from horizon import forms

View File

@ -15,7 +15,7 @@
from django.conf import settings
from django import forms
from django import http
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from horizon import forms as hforms
from horizon.utils import functions as utils

View File

@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
import horizon

View File

@ -12,11 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from django.conf.urls import url
from django.urls import re_path
from adjutant_ui.content.signup import views
urlpatterns = [
url(r'^$', views.SignupFormView.as_view(), name='index'),
url(r'^submitted/?$', views.signup_sent_view, name='submitted'),
re_path(r'^$', views.SignupFormView.as_view(), name='index'),
re_path(r'^submitted/?$', views.signup_sent_view, name='submitted'),
]

View File

@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from horizon import forms
from horizon import messages

View File

@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
import horizon

View File

@ -12,8 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ungettext_lazy
from django.utils.translation import gettext_lazy as _
from django.utils.translation import ngettext_lazy
from horizon import exceptions
from horizon import tables
@ -26,7 +26,7 @@ class CancelTask(tables.DeleteAction):
@staticmethod
def action_present(count):
return ungettext_lazy(
return ngettext_lazy(
u"Cancel Task",
u"Cancel Tasks",
count
@ -34,7 +34,7 @@ class CancelTask(tables.DeleteAction):
@staticmethod
def action_past(count):
return ungettext_lazy(
return ngettext_lazy(
u"Cancelled Task",
u"Cancelled Tasks",
count
@ -61,7 +61,7 @@ class ApproveTask(tables.BatchAction):
@staticmethod
def action_present(count):
return ungettext_lazy(
return ngettext_lazy(
u"Approve Task",
u"Approve Tasks",
count
@ -69,7 +69,7 @@ class ApproveTask(tables.BatchAction):
@staticmethod
def action_past(count):
return ungettext_lazy(
return ngettext_lazy(
u"Approved Task",
u"Approved Tasks",
count
@ -95,7 +95,7 @@ class ReissueToken(tables.BatchAction):
@staticmethod
def action_present(count):
return ungettext_lazy(
return ngettext_lazy(
u"Reissue Token",
u"Reissue Tokens",
count
@ -103,7 +103,7 @@ class ReissueToken(tables.BatchAction):
@staticmethod
def action_past(count):
return ungettext_lazy(
return ngettext_lazy(
u"Reissued Token",
u"Reissued Tokens",
count
@ -128,7 +128,7 @@ class RevalidateTask(tables.BatchAction):
@staticmethod
def action_present(count):
return ungettext_lazy(
return ngettext_lazy(
u"Rerun Validation",
u"Rerun Validation",
count
@ -136,7 +136,7 @@ class RevalidateTask(tables.BatchAction):
@staticmethod
def action_past(count):
return ungettext_lazy(
return ngettext_lazy(
u"Validation run",
u"Validation run",
count
@ -162,7 +162,7 @@ class ReapproveTask(ApproveTask):
@staticmethod
def action_present(count):
return ungettext_lazy(
return ngettext_lazy(
u"Reapprove Task",
u"Reapprove Tasks",
count
@ -170,7 +170,7 @@ class ReapproveTask(ApproveTask):
@staticmethod
def action_past(count):
return ungettext_lazy(
return ngettext_lazy(
u"Reapproved Task",
u"Reapproved Tasks",
count

View File

@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from horizon import exceptions
from horizon import tabs

View File

@ -13,16 +13,16 @@
# limitations under the License.
from django.conf.urls import url
from django.urls import re_path
from adjutant_ui.content.tasks import views
urlpatterns = [
url(r'^(?P<task_id>[^/]+)/$',
views.TaskDetailView.as_view(),
name='detail'),
url(r'^(?P<task_id>[^/]+)/update/$',
views.UpdateTaskView.as_view(), name='update'),
url(r'^$', views.IndexView.as_view(), name='index'),
re_path(r'^(?P<task_id>[^/]+)/$',
views.TaskDetailView.as_view(),
name='detail'),
re_path(r'^(?P<task_id>[^/]+)/update/$',
views.UpdateTaskView.as_view(), name='update'),
re_path(r'^$', views.IndexView.as_view(), name='index'),
]

View File

@ -13,7 +13,7 @@
# limitations under the License.
from django.urls import reverse
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from horizon import exceptions
from horizon import forms

View File

@ -15,7 +15,7 @@
from django.conf import settings
from django.forms import ValidationError # noqa
from django import http
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from django.views.decorators.debug import sensitive_variables # noqa
from horizon import exceptions

View File

@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
import horizon

View File

@ -12,11 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from django.conf.urls import url
from django.urls import re_path
from adjutant_ui.content.token import views
urlpatterns = [
url(r'^(?P<token>\w+)/?$', views.submit_token_router,
name='token_verify'),
re_path(r'^(?P<token>\w+)/?$', views.submit_token_router,
name='token_verify'),
]

View File

@ -15,7 +15,7 @@
from django.conf import settings
from django import http
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from horizon import exceptions
from horizon import forms

View File

@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
import horizon

View File

@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
import horizon

View File

@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
import horizon

View File

@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
import horizon

View File

@ -1,4 +1,4 @@
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
# The slug of the panel group to be added to HORIZON_CONFIG. Required.
PANEL_GROUP = 'access_control'

View File

@ -15,7 +15,7 @@
from django.conf import settings
from django import template
from django.utils.translation import ugettext_lazy
from django.utils.translation import gettext_lazy
register = template.Library()
@ -34,7 +34,7 @@ def relabel_username_field(context):
if (hasattr(settings, 'USERNAME_IS_EMAIL') and
getattr(settings, 'USERNAME_IS_EMAIL')):
try:
context['form'].fields['username'].label = ugettext_lazy('Email')
context['form'].fields['username'].label = gettext_lazy('Email')
except Exception:
pass
return u""

View File

@ -412,7 +412,6 @@ function run_integration_tests {
function babel_extract {
DOMAIN=$1
KEYWORDS="-k gettext_noop -k gettext_lazy -k ngettext_lazy:1,2"
KEYWORDS+=" -k ugettext_noop -k ugettext_lazy -k ungettext_lazy:1,2"
KEYWORDS+=" -k npgettext:1c,2,3 -k pgettext_lazy:1c,2 -k npgettext_lazy:1c,2,3"
mkdir -p locale

View File

@ -65,7 +65,7 @@ import_exceptions = collections.defaultdict,
django.conf.settings,
django.conf.urls.include,
django.conf.urls.patterns,
django.conf.urls.url,
django.urls.re_path,
django.urls.reverse,
django.urls.reverse_lazy,
django.template.loader.render_to_string,
@ -78,7 +78,7 @@ import_exceptions = collections.defaultdict,
django.utils.safestring.mark_safe,
django.utils.translation.npgettext_lazy,
django.utils.translation.pgettext_lazy,
django.utils.translation.ugettext_lazy,
django.utils.translation.ungettext_lazy,
django.utils.translation.gettext_lazy,
django.utils.translation.ngettext_lazy,
operator.attrgetter,
StringIO.StringIO