Skip to content

Commit 2e560e1

Browse files
committed
Fix Django schema deprecation
1 parent d374d88 commit 2e560e1

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

devel/forms.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from django.template import loader
1212

1313
from .models import UserProfile
14+
from django.db.models import URLField
1415

1516

1617
class ProfileForm(forms.Form):
@@ -32,6 +33,13 @@ def clean(self):
3233
return self.cleaned_data
3334

3435

36+
# Assume all URLField will be HTTPS if not specified.
37+
def _urlfields_assume_https(db_field, **kwargs):
38+
if isinstance(db_field, URLField):
39+
kwargs["assume_scheme"] = "http"
40+
return db_field.formfield(**kwargs)
41+
42+
3543
class UserProfileForm(forms.ModelForm):
3644
def clean_pgp_key(self):
3745
data = self.cleaned_data['pgp_key']
@@ -46,6 +54,7 @@ class Meta:
4654
widgets = {
4755
'yob': NumberInput(attrs={'min': 1950, 'max': date.today().year - 10}),
4856
}
57+
formfield_callback = _urlfields_assume_https
4958

5059

5160
class NewUserForm(forms.ModelForm):
@@ -58,6 +67,7 @@ class NewUserForm(forms.ModelForm):
5867
class Meta:
5968
model = UserProfile
6069
exclude = ('picture', 'user')
70+
formfield_callback = _urlfields_assume_https
6171

6272
def __init__(self, *args, **kwargs):
6373
super(NewUserForm, self).__init__(*args, **kwargs)

0 commit comments

Comments
 (0)