1
0
mirror of https://github.com/django/django.git synced 2025-10-24 22:26:08 +00:00

Fixed #317 -- SlugField now accepts hyphens. Thanks, Sune

git-svn-id: http://code.djangoproject.com/svn/django/trunk@968 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty
2005-10-20 04:20:52 +00:00
parent bf5dce64de
commit 539e53ccf1
4 changed files with 13 additions and 9 deletions

View File

@@ -500,7 +500,7 @@ class PositiveSmallIntegerField(IntegerField):
class SlugField(Field):
def __init__(self, *args, **kwargs):
kwargs['maxlength'] = 50
kwargs.setdefault('validator_list', []).append(validators.isAlphaNumeric)
kwargs.setdefault('validator_list', []).append(validators.isSlug)
# Set db_index=True unless it's been set manually.
if not kwargs.has_key('db_index'):
kwargs['db_index'] = True

View File

@@ -21,6 +21,7 @@ email_re = re.compile(r'^[-\w.+]+@\w[\w.-]+$')
integer_re = re.compile(r'^-?\d+$')
ip4_re = re.compile(r'^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$')
phone_re = re.compile(r'^[A-PR-Y0-9]{3}-[A-PR-Y0-9]{3}-[A-PR-Y0-9]{4}$', re.IGNORECASE)
slug_re = re.compile(r'^[-\w]+$')
url_re = re.compile(r'^http://\S+$')
from django.conf.settings import JING_PATH
@@ -57,7 +58,11 @@ def isAlphaNumeric(field_data, all_data):
def isAlphaNumericURL(field_data, all_data):
if not alnumurl_re.search(field_data):
raise ValidationError, "This value must contain only letters, numbers, underscores and slashes."
raise ValidationError, "This value must contain only letters, numbers, underscores or slashes."
def isSlug(field_data, all_data):
if not slug_re.search(field_data):
raise ValidationError, "This value must contain only letters, numbers, underscores or hyphens."
def isLowerCase(field_data, all_data):
if field_data.lower() != field_data: