Django

Code

Changeset 5223

Show
Ignore:
Timestamp:
05/14/07 02:04:31 (1 year ago)
Author:
mtredinnick
Message:

unicode: Made various changes to prevent actual and potential Python 2.3
compatibility problems. Refs #3582.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/unicode/django/db/models/base.py

    r5203 r5223  
    8585 
    8686    def __repr__(self): 
    87         return smart_str(u'<%s: %s>' % (self.__class__.__name__, self)) 
     87        return smart_str(u'<%s: %s>' % (self.__class__.__name__, unicode(self))) 
    8888 
    8989    def __str__(self): 
  • django/branches/unicode/django/newforms/util.py

    r4918 r5223  
    1919    def as_ul(self): 
    2020        if not self: return u'' 
    21         return u'<ul class="errorlist">%s</ul>' % ''.join([u'<li>%s%s</li>' % (k, v) for k, v in self.items()]) 
     21        return u'<ul class="errorlist">%s</ul>' % ''.join([u'<li>%s%s</li>' % (k, smart_unicode(v)) for k, v in self.items()]) 
    2222 
    2323    def as_text(self): 
    24         return u'\n'.join([u'* %s\n%s' % (k, u'\n'.join([u'  * %s' % i for i in v])) for k, v in self.items()]) 
     24        return u'\n'.join([u'* %s\n%s' % (k, u'\n'.join([u'  * %s' % smart_unicode(i) for i in v])) for k, v in self.items()]) 
    2525 
    2626class ErrorList(list): 
     
    3333    def as_ul(self): 
    3434        if not self: return u'' 
    35         return u'<ul class="errorlist">%s</ul>' % ''.join([u'<li>%s</li>' % e for e in self]) 
     35        return u'<ul class="errorlist">%s</ul>' % ''.join([u'<li>%s</li>' % smart_unicode(e) for e in self]) 
    3636 
    3737    def as_text(self): 
    3838        if not self: return u'' 
    39         return u'\n'.join([u'* %s' % e for e in self]) 
     39        return u'\n'.join([u'* %s' % smart_unicode(e) for e in self]) 
    4040 
    4141class ValidationError(Exception): 
  • django/branches/unicode/django/newforms/widgets.py

    r5126 r5223  
    254254    def __unicode__(self): 
    255255        "Outputs a <ul> for this set of radio fields." 
    256         return u'<ul>\n%s\n</ul>' % u'\n'.join([u'<li>%s</li>' % w for w in self]) 
     256        return u'<ul>\n%s\n</ul>' % u'\n'.join([u'<li>%s</li>' % smart_unicode(w) for w in self]) 
    257257 
    258258class RadioSelect(Select): 
  • django/branches/unicode/django/template/defaultfilters.py

    r5081 r5223  
    171171    "Escapes a value for use in a URL" 
    172172    import urllib 
    173     return urllib.quote(value).decode('utf-8'
     173    return smart_unicode(urllib.quote(value)
    174174urlencode = stringfilter(urlencode) 
    175175 
     
    365365        indent = u'\t' * tabs 
    366366        if value[1]: 
    367             return u'%s<li>%s\n%s<ul>\n%s\n%s</ul>\n%s</li>' % (indent, value[0], indent, 
     367            return u'%s<li>%s\n%s<ul>\n%s\n%s</ul>\n%s</li>' % (indent, smart_unicode(value[0]), indent, 
    368368                u'\n'.join([_helper(v, tabs+1) for v in value[1]]), indent, indent) 
    369369        else: 
    370             return u'%s<li>%s</li>' % (indent, value[0]
     370            return u'%s<li>%s</li>' % (indent, smart_unicode(value[0])
    371371    return _helper(value, 1) 
    372372 
     
    547547        return pformat(value) 
    548548    except Exception, e: 
    549         return u"Error in formatting:%s" % e 
     549        return u"Error in formatting:%s" % smart_unicode(e) 
    550550 
    551551# Syntax: register.filter(name of filter, callback) 
  • django/branches/unicode/django/utils/html.py

    r5056 r5223  
    3333    value = re.sub(r'\r\n|\r|\n', '\n', value) # normalize newlines 
    3434    paras = re.split('\n{2,}', value) 
    35     paras = ['<p>%s</p>' % p.strip().replace('\n', '<br />') for p in paras] 
     35    paras = [u'<p>%s</p>' % p.strip().replace('\n', '<br />') for p in paras] 
    3636    return u'\n\n'.join(paras) 
    3737 
     
    5454def urlize(text, trim_url_limit=None, nofollow=False): 
    5555    """ 
    56     Converts any URLs in text into clickable links. Works on http://, https:// and 
    57     www. links. Links can have trailing punctuation (periods, commas, close-parens) 
    58     and leading punctuation (opening parens) and it'll still do the right thing. 
     56    Converts any URLs in text into clickable links. Works on http://, https:// 
     57    and www. links. Links can have trailing punctuation (periods, commas, 
     58    close-parens) and leading punctuation (opening parens) and it'll still do 
     59    the right thing. 
    5960 
    6061    If trim_url_limit is not None, the URLs in link text will be limited to 
    6162    trim_url_limit characters. 
    6263 
    63     If nofollow is True, the URLs in link text will get a rel="nofollow" attribute. 
     64    If nofollow is True, the URLs in link text will get a rel="nofollow" 
     65    attribute. 
    6466    """ 
    6567    trim_url = lambda x, limit=trim_url_limit: limit is not None and (x[:limit] + (len(x) >=limit and '...' or ''))  or x