Opened 17 years ago

Closed 14 years ago

#5331 closed (fixed)

URLField should add http:// if no scheme given

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

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 Chris Beaven 17 years ago.
urlfield.2.patch (1.7 KB ) - added by Chris Beaven 17 years ago.
with tests

Download all attachments as: .zip

Change History (7)

by Chris Beaven, 17 years ago

Attachment: urlfield.patch added

comment:1 by Chris Beaven, 17 years ago

Triage Stage: UnreviewedDesign decision needed

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

by Chris Beaven, 17 years ago

Attachment: urlfield.2.patch added

with tests

comment:2 by Simon G. <dev@…>, 17 years ago

Triage Stage: Design decision neededReady for checkin

Ready to go.

comment:3 by Russell Keith-Magee, 17 years ago

Resolution: fixed
Status: newclosed

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

comment:4 by Adam Alton, 14 years ago

Resolution: fixed
Status: closedreopened

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:

kwargsform_class = forms.URLField

return super(URLField, self).formfield(kwargs)

Version 2, edited 14 years ago by Adam Alton (previous) (next) (diff)

comment:5 by Russell Keith-Magee, 14 years ago

Has patch: unset
Resolution: fixed
Status: reopenedclosed
Triage Stage: Ready for checkinAccepted

@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.

Note: See TracTickets for help on using tickets.
Back to Top