1111from django .template import loader
1212
1313from .models import UserProfile
14+ from django .db .models import URLField
1415
1516
1617class ProfileForm (forms .Form ):
@@ -31,6 +32,11 @@ def clean(self):
3132 raise forms .ValidationError ('Passwords do not match.' )
3233 return self .cleaned_data
3334
35+ def _urlfields_assume_https (db_field , ** kwargs ):
36+ if isinstance (db_field , URLField ):
37+ kwargs ["assume_scheme" ] = "https"
38+ return db_field .formfield (** kwargs )
39+
3440
3541class UserProfileForm (forms .ModelForm ):
3642 def clean_pgp_key (self ):
@@ -46,6 +52,7 @@ class Meta:
4652 widgets = {
4753 'yob' : NumberInput (attrs = {'min' : 1950 , 'max' : date .today ().year - 10 }),
4854 }
55+ formfield_callback = _urlfields_assume_https
4956
5057
5158class NewUserForm (forms .ModelForm ):
@@ -58,6 +65,7 @@ class NewUserForm(forms.ModelForm):
5865 class Meta :
5966 model = UserProfile
6067 exclude = ('picture' , 'user' )
68+ formfield_callback = _urlfields_assume_https
6169
6270 def __init__ (self , * args , ** kwargs ):
6371 super (NewUserForm , self ).__init__ (* args , ** kwargs )
0 commit comments