﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
18120	add DomainNameField model Field type to validate and store Internet Domain Names	michele	nobody	"In django models you can store an URL, but not a domain name. This patch adds a DomainNameField class to address that.

DomainNameField accepts:
* traditional domain names in ASCII form
* Internationalized Domain Names in IDNA form (ASCII encoded)
* Internationalized Domain Names in UTF form

DomainNameField always stores values in ASCII format by encoding and decoding UTF IDNs as needed.

Implementation notes:
* based on CharField and DomainNameValidator (see #18119)
* an implicit max_length=255 is added to CharField to propagate the Domain constraint down to the db schema
* naming: accept_idna might be renamed to ""accept_idn"" or simply ""idn"" for Internationalized Domain Name

This passes successfully a buch of tests:

{{{
class Zone(models.Model):
    name = models.DomainNameField()

plain_domain = 'foo.com'
idn_domain_good = 'xn--1lq90ic7fzpc.xn--fiqs8s'.decode('idna')   # a IDN domain in UTF format
idn_domain_bad = idn_domain + '#'

Zone(name=plain_domain).full_clean()
# ok!
Zone(name=idn_domain_good).full_clean()
# ok!
Zone(name=idn_domain_bad).full_clean()
# raises ValidationError ok!
Zone(name=idn_domain).save()
# selecting from db yields:
xn--1lq90ic7fzpc.xn--fiqs8s
# ok!

class Zone(models.Model):
    name = models.DomainNameField(accept_idna=False)

Zone(name=idn_domain_good).full_clean()
# raises ValidationError ok!
}}}

I'll implement these in a suitable test module if django.db will start one.

Work for this and DomainNameValidator was sponsored by [http://www.buddyns.com BuddyNS]."	Uncategorized	closed	Database layer (models, ORM)	1.4	Normal	wontfix	domain		Unreviewed	0	0	0	0	0	0
