Django

Code

Changeset 968

Show
Ignore:
Timestamp:
10/19/05 23:20:52 (3 years ago)
Author:
adrian
Message:

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

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/contrib/admin/media/js/urlify.js

    r96 r968  
    11function URLify(s, num_chars) { 
    22    // changes, e.g., "Petty theft" to "petty_theft" 
    3      
    43    // 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", 
    87                  "with"]; 
    98    r = new RegExp('\\b(' + removelist.join('|') + ')\\b', 'gi'); 
    109    s = s.replace(r, ''); 
    11     s = s.replace(/[^\w\s]/g, '');   // remove unneeded chars 
     10    s = s.replace(/[^\w\s-]/g, '');  // remove unneeded chars 
    1211    s = s.replace(/^\s+|\s+$/g, ''); // trim leading/trailing spaces 
    1312    s = s.replace(/\s+/g, '_');      // convert spaces to underscores 
  • django/trunk/django/core/meta/fields.py

    r846 r968  
    501501    def __init__(self, *args, **kwargs): 
    502502        kwargs['maxlength'] = 50 
    503         kwargs.setdefault('validator_list', []).append(validators.isAlphaNumeric
     503        kwargs.setdefault('validator_list', []).append(validators.isSlug
    504504        # Set db_index=True unless it's been set manually. 
    505505        if not kwargs.has_key('db_index'): 
  • django/trunk/django/core/validators.py

    r712 r968  
    2222ip4_re = re.compile(r'^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$') 
    2323phone_re = re.compile(r'^[A-PR-Y0-9]{3}-[A-PR-Y0-9]{3}-[A-PR-Y0-9]{4}$', re.IGNORECASE) 
     24slug_re = re.compile(r'^[-\w]+$') 
    2425url_re = re.compile(r'^http://\S+$') 
    2526 
     
    5859def isAlphaNumericURL(field_data, all_data): 
    5960    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 
     63def 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." 
    6166 
    6267def isLowerCase(field_data, all_data): 
  • django/trunk/docs/model-api.txt

    r967 r968  
    370370``SlugField`` 
    371371    "Slug" is a newspaper term. A slug is a short label for something, 
    372     containing only letters, numbers and underscores. They're generally used in 
    373     URLs. 
     372    containing only letters, numbers, underscores or hyphens. They're generally 
     373    used in URLs. 
    374374 
    375375    Implies ``maxlength=50`` and ``db_index=True``.