#36923: URLField mangles mailto: URLs
---------------------------------+-----------------------------------------
     Reporter:  waveywhite       |                     Type:  Uncategorized
       Status:  new              |                Component:  Forms
      Version:  5.2              |                 Severity:  Normal
     Keywords:  mailto urlfield  |             Triage Stage:  Unreviewed
    Has patch:  0                |      Needs documentation:  0
  Needs tests:  0                |  Patch needs improvement:  0
Easy pickings:  0                |                    UI/UX:  0
---------------------------------+-----------------------------------------
 Having derived from django.forms.URLField and django.models.URLField to
 set up a form that can handle mailto URLs, I'm finding that the URL gets
 mangled. Entering "mailto:[email protected]"; results in
 "mailto://[email protected]";.

 This was encountered while creating models for a Wagtail site. Wagtail
 uses Django's models and form fields within its framework.

 My modified URLFields:

 {{{
 from django import forms
 from django.db import models

 class ContactUrlFormField(forms.URLField):
     default_validators = [
         validators.URLValidator(schemes=['http', 'https', 'mailto',
 'tel'])
     ]

 class ContactUrlField(models.URLField):
     default_validators = [
         validators.URLValidator(schemes=['http', 'https', 'mailto',
 'tel'])
     ]

     def formfield(self, **kwargs):
         return super().formfield(
             **{
                 "form_class": ContactUrlFormField,
                 **kwargs,
             }
         )
 }}}

 NB. It would be great to have a way of defining which URL schemes are
 allowed as an option in the model field and then have it picked up by the
 form field automatically.
-- 
Ticket URL: <https://code.djangoproject.com/ticket/36923>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/django-updates/0107019c51be4db3-4b4eae8a-9ffc-4543-86a4-ff8da923f9b1-000000%40eu-central-1.amazonses.com.

Reply via email to