Code

Opened 7 years ago

Closed 3 years ago

#5331 closed (fixed)

URLField should add http:// if no scheme given

Reported by: SmileyChris Owned by: nobody
Component: Forms Version: master
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

The usual scheme for a URLField is http://. You're average user will often not enter the scheme of their URL so the clean method should just prepend 'http://' if no scheme was given.

Attachments (2)

urlfield.patch (548 bytes) - added by SmileyChris 7 years ago.
urlfield.2.patch (1.7 KB) - added by SmileyChris 7 years ago.
with tests

Download all attachments as: .zip

Change History (7)

Changed 7 years ago by SmileyChris

comment:1 Changed 7 years ago by SmileyChris

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Design decision needed

Makes sense to me, but I'll pass it past the core developers.

Changed 7 years ago by SmileyChris

with tests

comment:2 Changed 7 years ago by Simon G. <dev@…>

  • Triage Stage changed from Design decision needed to Ready for checkin

Ready to go.

comment:3 Changed 7 years ago by russellm

  • Resolution set to fixed
  • Status changed from new to closed

(In [6173]) Fixed #5331 -- Modified newforms URLField to prepend http:// if no protocol is specified by the user. Thanks, SmileyChris?.

comment:4 Changed 3 years ago by adamalton

  • Resolution fixed deleted
  • Status changed from closed to reopened

django.db.models.URLField doesn't have a custom 'formfield' method, and so by default it uses django.forms.CharField as its form field. And so django.forms.URLField never even gets used, so the patch submitted above is currently not having any effect (Django 1.3 alpha).

It needs a 'formfield' method adding to django.db.models.URLField...

#django/db/models/fields/__init__.py
class URLField:
    #snip
    def formfield(self, **kwargs):
        if 'form_class' not in kwargs:
            kwargs['form_class'] = forms.URLField
        return super(URLField, self).formfield(**kwargs)
Last edited 3 years ago by adamalton (previous) (diff)

comment:5 Changed 3 years ago by russellm

  • Has patch unset
  • Resolution set to fixed
  • Status changed from reopened to closed
  • Triage Stage changed from Ready for checkin to Accepted

@adamalton -- I don't know what code you're looking at, but URLField *does* have a custom formfield method, there is a unit test validating that http prefixing works as intended, and a quick test verifies that the field is working as intended.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.