Ticket #317: slug.patch
File slug.patch, 2.5 KB (added by , 19 years ago) |
---|
-
django/conf/admin_media/js/urlify.js
8 8 "with"]; 9 9 r = new RegExp('\\b(' + removelist.join('|') + ')\\b', 'gi'); 10 10 s = s.replace(r, ''); 11 s = s.replace(/[^\w\s ]/g, ''); // remove unneeded chars11 s = s.replace(/[^\w\s-]/g, ''); // remove unneeded chars 12 12 s = s.replace(/^\s+|\s+$/g, ''); // trim leading/trailing spaces 13 s = s.replace(/\s+/g, ' _'); // convert spaces to underscores13 s = s.replace(/\s+/g, '-'); // convert spaces to underscores 14 14 s = s.toLowerCase(); // convert to lowercase 15 15 return s.substring(0, num_chars);// trim to first num_chars chars 16 } 17 No newline at end of file 16 } -
django/core/meta/fields.py
485 485 class SlugField(Field): 486 486 def __init__(self, *args, **kwargs): 487 487 kwargs['maxlength'] = 50 488 kwargs.setdefault('validator_list', []).append(validators.is AlphaNumeric)488 kwargs.setdefault('validator_list', []).append(validators.isSlug) 489 489 # Set db_index=True unless it's been set manually. 490 490 if not kwargs.has_key('db_index'): 491 491 kwargs['db_index'] = True -
django/core/validators.py
14 14 _timere = r'(?:[01]?[0-9]|2[0-3]):[0-5][0-9](?::[0-5][0-9])?' 15 15 alnum_re = re.compile(r'^\w+$') 16 16 alnumurl_re = re.compile(r'^[\w/]+$') 17 slug_re = re.compile(r'^[\w.-]+$') 17 18 ansi_date_re = re.compile('^%s$' % _datere) 18 19 ansi_time_re = re.compile('^%s$' % _timere) 19 20 ansi_datetime_re = re.compile('^%s %s$' % (_datere, _timere)) … … 58 59 if not alnumurl_re.search(field_data): 59 60 raise ValidationError, "This value must contain only letters, numbers, underscores and slashes." 60 61 62 def isSlug(field_data, all_data): 63 if not slug_re.search(field_data): 64 raise ValidationError, "This value must contain only letters, numbers, underscores and dashes." 65 61 66 def isLowerCase(field_data, all_data): 62 67 if field_data.lower() != field_data: 63 68 raise ValidationError, "Uppercase letters are not allowed here."