1111from django .template import loader
1212
1313from .models import UserProfile
14+ from django .db .models import URLField
1415
1516
1617class 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+
3543class 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
5160class 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