Changeset 968
- Timestamp:
- 10/19/05 23:20:52 (3 years ago)
- Files:
-
- django/trunk/django/contrib/admin/media/js/urlify.js (modified) (1 diff)
- django/trunk/django/core/meta/fields.py (modified) (1 diff)
- django/trunk/django/core/validators.py (modified) (2 diffs)
- django/trunk/docs/model-api.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/contrib/admin/media/js/urlify.js
r96 r968 1 1 function URLify(s, num_chars) { 2 2 // changes, e.g., "Petty theft" to "petty_theft" 3 4 3 // remove all these words from the string before urlifying 5 removelist = ["a", "an", "as", "at", "before", "but", "by", "for", "from", 6 "is", "in", "into", "like", "of", "off", "on", "onto", "per", 7 "since", "than", "the", "this", "that", "to", "up", "via", 4 removelist = ["a", "an", "as", "at", "before", "but", "by", "for", "from", 5 "is", "in", "into", "like", "of", "off", "on", "onto", "per", 6 "since", "than", "the", "this", "that", "to", "up", "via", 8 7 "with"]; 9 8 r = new RegExp('\\b(' + removelist.join('|') + ')\\b', 'gi'); 10 9 s = s.replace(r, ''); 11 s = s.replace(/[^\w\s ]/g, '');// remove unneeded chars10 s = s.replace(/[^\w\s-]/g, ''); // remove unneeded chars 12 11 s = s.replace(/^\s+|\s+$/g, ''); // trim leading/trailing spaces 13 12 s = s.replace(/\s+/g, '_'); // convert spaces to underscores django/trunk/django/core/meta/fields.py
r846 r968 501 501 def __init__(self, *args, **kwargs): 502 502 kwargs['maxlength'] = 50 503 kwargs.setdefault('validator_list', []).append(validators.is AlphaNumeric)503 kwargs.setdefault('validator_list', []).append(validators.isSlug) 504 504 # Set db_index=True unless it's been set manually. 505 505 if not kwargs.has_key('db_index'): django/trunk/django/core/validators.py
r712 r968 22 22 ip4_re = re.compile(r'^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$') 23 23 phone_re = re.compile(r'^[A-PR-Y0-9]{3}-[A-PR-Y0-9]{3}-[A-PR-Y0-9]{4}$', re.IGNORECASE) 24 slug_re = re.compile(r'^[-\w]+$') 24 25 url_re = re.compile(r'^http://\S+$') 25 26 … … 58 59 def isAlphaNumericURL(field_data, all_data): 59 60 if not alnumurl_re.search(field_data): 60 raise ValidationError, "This value must contain only letters, numbers, underscores and slashes." 61 raise ValidationError, "This value must contain only letters, numbers, underscores or slashes." 62 63 def isSlug(field_data, all_data): 64 if not slug_re.search(field_data): 65 raise ValidationError, "This value must contain only letters, numbers, underscores or hyphens." 61 66 62 67 def isLowerCase(field_data, all_data): django/trunk/docs/model-api.txt
r967 r968 370 370 ``SlugField`` 371 371 "Slug" is a newspaper term. A slug is a short label for something, 372 containing only letters, numbers and underscores. They're generally used in373 URLs.372 containing only letters, numbers, underscores or hyphens. They're generally 373 used in URLs. 374 374 375 375 Implies ``maxlength=50`` and ``db_index=True``.
