Skip to content
This repository has been archived by the owner on Sep 3, 2024. It is now read-only.

is_safe_url deprecated in django 4.0 #16

Merged
merged 1 commit into from
Aug 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions dc_signup_form/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from django.contrib import messages
from django.urls import reverse, NoReverseMatch
from django.utils.http import is_safe_url
from django.views.generic import FormView
from .backends import (
LocalDbBackend,
Expand All @@ -9,6 +8,13 @@
)


def get_http(request, host):
try:
from django.utils.http import is_safe_url
return is_safe_url(request, host)
except ImportError:
from django.utils.http import url_has_allowed_host_and_scheme
return url_has_allowed_host_and_scheme(request, host)
class SignupFormView(FormView):
mailing_lists = [
'main_list', 'election_reminders'
Expand Down Expand Up @@ -42,9 +48,9 @@ def get_success_url(self):
election_reminders_signup_view = ''

try:
source_url_safe = is_safe_url(source_url, allowed_hosts=None)
source_url_safe = get_http(source_url, allowed_hosts=None)
except TypeError:
source_url_safe = is_safe_url(source_url)
source_url_safe = get_http(source_url)
if source_url_safe and\
source_url != mailing_list_signup_view and\
source_url != election_reminders_signup_view:
Expand Down