1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

[5.0.x] Refs #34380 -- Added FORMS_URLFIELD_ASSUME_HTTPS transitional setting.

This allows early adoption of the new default "https".

Backport of a4931cd75a from main.
This commit is contained in:
Mariusz Felisiak
2023-11-28 20:04:21 +01:00
parent 432bfa2615
commit 92af3d4d23
9 changed files with 113 additions and 13 deletions

View File

@@ -15,6 +15,7 @@ from decimal import Decimal, DecimalException
from io import BytesIO
from urllib.parse import urlsplit, urlunsplit
from django.conf import settings
from django.core import validators
from django.core.exceptions import ValidationError
from django.forms.boundfield import BoundField
@@ -762,14 +763,19 @@ class URLField(CharField):
def __init__(self, *, assume_scheme=None, **kwargs):
if assume_scheme is None:
warnings.warn(
"The default scheme will be changed from 'http' to 'https' in Django "
"6.0. Pass the forms.URLField.assume_scheme argument to silence this "
"warning.",
RemovedInDjango60Warning,
stacklevel=2,
)
assume_scheme = "http"
if settings.FORMS_URLFIELD_ASSUME_HTTPS:
assume_scheme = "https"
else:
warnings.warn(
"The default scheme will be changed from 'http' to 'https' in "
"Django 6.0. Pass the forms.URLField.assume_scheme argument to "
"silence this warning, or set the FORMS_URLFIELD_ASSUME_HTTPS "
"transitional setting to True to opt into using 'https' as the new "
"default scheme.",
RemovedInDjango60Warning,
stacklevel=2,
)
assume_scheme = "http"
# RemovedInDjango60Warning: When the deprecation ends, replace with:
# self.assume_scheme = assume_scheme or "https"
self.assume_scheme = assume_scheme