Django

Code

Changeset 5609

Show
Ignore:
Timestamp:
07/04/07 07:11:04 (2 years ago)
Author:
mtredinnick
Message:

Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.

Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk

    • Property svnmerge-integrated set to /django/trunk:1-5600
  • django/trunk/AUTHORS

    r5593 r5609  
    114114    Owen Griffiths 
    115115    Espen Grindhaug <http://grindhaug.org/> 
     116    Thomas Güttler <hv@tbz-pariv.de> 
    116117    Brian Harring <ferringb@gmail.com> 
    117118    Brant Harris 
     
    148149    Joseph Kocherhans 
    149150    konrad@gwu.edu 
     151    kurtiss@meetro.com 
    150152    lakin.wecker@gmail.com 
    151153    Nick Lane <nick.lane.au@gmail.com> 
  • django/trunk/django/bin/make-messages.py

    r5084 r5609  
    104104                        thefile = '%s.py' % file 
    105105                    if verbose: sys.stdout.write('processing file %s in %s\n' % (file, dirpath)) 
    106                     cmd = 'xgettext %s -d %s -L Python --keyword=gettext_noop --keyword=gettext_lazy --keyword=ngettext_lazy:1,2 --from-code UTF-8 -o - "%s"' % ( 
     106                    cmd = 'xgettext %s -d %s -L Python --keyword=gettext_noop --keyword=gettext_lazy --keyword=ngettext_lazy:1,2 --keyword=ugettext_noop --keyword=ugettext_lazy --keyword=ungettext_lazy:1,2 --from-code UTF-8 -o - "%s"' % ( 
    107107                        os.path.exists(potfile) and '--omit-header' or '', domain, os.path.join(dirpath, thefile)) 
    108108                    (stdin, stdout, stderr) = os.popen3(cmd, 'b') 
  • django/trunk/django/conf/global_settings.py

    r5523 r5609  
    9898DEFAULT_CHARSET = 'utf-8' 
    9999 
     100# Encoding of files read from disk (template and initial SQL files). 
     101FILE_CHARSET = 'utf-8' 
     102 
    100103# E-mail address that error messages come from. 
    101104SERVER_EMAIL = 'root@localhost' 
  • django/trunk/django/contrib/admin/filterspecs.py

    r4486 r5609  
    88 
    99from django.db import models 
     10from django.utils.encoding import smart_unicode, iri_to_uri 
     11from django.utils.translation import ugettext as _ 
    1012import datetime 
    1113 
     
    3840        t = [] 
    3941        if self.has_output(): 
    40             t.append(_('<h3>By %s:</h3>\n<ul>\n') % self.title()) 
     42            t.append(_(u'<h3>By %s:</h3>\n<ul>\n') % self.title()) 
    4143 
    4244            for choice in self.choices(cl): 
    43                 t.append('<li%s><a href="%s">%s</a></li>\n' % \ 
     45                t.append(u'<li%s><a href="%s">%s</a></li>\n' % \ 
    4446                    ((choice['selected'] and ' class="selected"' or ''), 
    45                      choice['query_string']
     47                     iri_to_uri(choice['query_string'])
    4648                     choice['display'])) 
    4749            t.append('</ul>\n\n') 
     
    7173        for val in self.lookup_choices: 
    7274            pk_val = getattr(val, self.field.rel.to._meta.pk.attname) 
    73             yield {'selected': self.lookup_val == str(pk_val), 
     75            yield {'selected': self.lookup_val == smart_unicode(pk_val), 
    7476                   'query_string': cl.get_query_string({self.lookup_kwarg: pk_val}), 
    7577                   'display': val} 
     
    8890               'display': _('All')} 
    8991        for k, v in self.field.choices: 
    90             yield {'selected': str(k) == self.lookup_val, 
     92            yield {'selected': smart_unicode(k) == self.lookup_val, 
    9193                    'query_string': cl.get_query_string({self.lookup_kwarg: k}), 
    9294                    'display': v} 
     
    169171               'display': _('All')} 
    170172        for val in self.lookup_choices: 
    171             val = str(val[self.field.name]) 
     173            val = smart_unicode(val[self.field.name]) 
    172174            yield {'selected': self.lookup_val == val, 
    173175                   'query_string': cl.get_query_string({self.field.name: val}), 
  • django/trunk/django/contrib/admin/media/js/urlify.js

    r4537 r5609  
     1var LATIN_MAP = 
     2{ 
     3    'À': 'A', 'Á': 'A', 'Â': 'A', 'Ã': 'A', 'Ä': 'A', 'Å': 'A', 'Æ': 'AE', 'Ç': 
     4    'C', 'È': 'E', 'É': 'E', 'Ê': 'E', 'Ë': 'E', 'Ì': 'I', 'Í': 'I', 'Î': 'I', 
     5    'Ï': 'I', 'Ð': 'D', 'Ñ': 'N', 'Ò': 'O', 'Ó': 'O', 'Ô': 'O', 'Õ': 'O', 'Ö': 
     6    'O', 'Ø': 'O', 'Ù': 'U', 'Ú': 'U', 'Û': 'U', 'Ü': 'U', 'Ý': 'Y', 'Þ': 'TH', 
     7    'ß': 'ss', 'à':'a', 'á':'a', 'â': 'a', 'ã': 'a', 'ä': 'a', 'å': 'a', 'æ': 
     8    'ae', 'ç': 'c', 'è': 'e', 'é': 'e', 'ê': 'e', 'ë': 'e', 'ì': 'i', 'í': 'i', 
     9    'î': 'i', 'ï': 'i', 'ð': 'o', 'ñ': 'n', 'ò': 'o', 'ó': 'o', 'ô': 'o', 'õ': 
     10    'o', 'ö': 'o', 'ø': 'o', 'ù': 'u', 'ú': 'u', 'û': 'u', 'ü': 'u', 'ý': 'y', 
     11    'þ': 'th', 'ÿ': 'y', 
     12} 
     13var LATIN_SYMBOLS_MAP = 
     14{ 
     15    '©':'(c)', 
     16} 
     17var GREEK_MAP = 
     18{ 
     19    'α':'a', 'β':'b', 'γ':'g', 'δ':'d', 'ε':'e', 'ζ':'z', 'η':'h', 'θ':'8', 
     20    'ι':'i', 'κ':'k', 'λ':'l', 'μ':'m', 'ν':'n', 'ξ':'3', 'ο':'o', 'π':'p', 
     21    'ρ':'r', 'σ':'s', 'τ':'t', 'υ':'y', 'φ':'f', 'χ':'x', 'ψ':'ps', 'ω':'w', 
     22    'ά':'a', 'έ':'e', 'ί':'i', 'ό':'o', 'ύ':'y', 'ή':'h', 'ώ':'w', 'ς':'s', 
     23    'ϊ':'i', 'ΰ':'y', 'ϋ':'y', 'ΐ':'i', 
     24    'Α':'A', 'Β':'B', 'Γ':'G', 'Δ':'D', 'Ε':'E', 'Ζ':'Z', 'Η':'H', 'Θ':'8', 
     25    'Ι':'I', 'Κ':'K', 'Λ':'L', 'Μ':'M', 'Ν':'N', 'Ξ':'3', 'Ο':'O', 'Π':'P', 
     26    'Ρ':'R', 'Σ':'S', 'Τ':'T', 'Υ':'Y', 'Φ':'F', 'Χ':'X', 'Ψ':'PS', 'Ω':'W', 
     27    'Ά':'A', 'Έ':'E', 'Ί':'I', 'Ό':'O', 'Ύ':'Y', 'Ή':'H', 'Ώ':'W', 'Ϊ':'I', 
     28    'Ϋ':'Y' 
     29} 
     30var TURKISH_MAP = { 
     31    'ş':'s', 'Ş':'S', 'ı':'i', 'İ':'I', 'ç':'c', 'Ç':'C', 'ü':'u', 'Ü':'U', 
     32    'ö':'o', 'Ö':'O', 'ğ':'g', 'Ğ':'G', 
     33} 
     34// var RUSSIAN_MAP = 
     35// { 
     36// } 
     37 
     38var ALL_DOWNCODE_MAPS=new Array() 
     39ALL_DOWNCODE_MAPS[0]=LATIN_MAP 
     40ALL_DOWNCODE_MAPS[1]=LATIN_SYMBOLS_MAP 
     41ALL_DOWNCODE_MAPS[2]=GREEK_MAP 
     42ALL_DOWNCODE_MAPS[3]=TURKISH_MAP 
     43//ALL_DOWNCODE_MAPS[4]=RUSSIAN_MAP 
     44 
     45var Downcoder = new Object(); 
     46Downcoder.Initialize = function() 
     47{ 
     48    if (Downcoder.map) // already made 
     49        return ; 
     50    Downcoder.map ={} 
     51    Downcoder.chars = '' ; 
     52    for(var i in ALL_DOWNCODE_MAPS) 
     53    { 
     54        var lookup = ALL_DOWNCODE_MAPS[i] 
     55        for (var c in lookup) 
     56        { 
     57            Downcoder.map[c] = lookup[c] ; 
     58            Downcoder.chars += c ; 
     59        } 
     60     } 
     61    Downcoder.regex = new RegExp('[' + Downcoder.chars + ']|[^' + Downcoder.chars + ']+','g') ; 
     62} 
     63 
     64downcode= function( slug ) 
     65{ 
     66    Downcoder.Initialize() ; 
     67    var downcoded ="" 
     68    var pieces = slug.match(Downcoder.regex); 
     69    if(pieces) 
     70    { 
     71        for (var i = 0 ; i < pieces.length ; i++) 
     72        { 
     73            if (pieces[i].length == 1) 
     74            { 
     75                var mapped = Downcoder.map[pieces[i]] ; 
     76                if (mapped != null) 
     77                { 
     78                    downcoded+=mapped; 
     79                    continue ; 
     80                } 
     81            } 
     82            downcoded+=pieces[i]; 
     83        } 
     84    } 
     85    else 
     86    { 
     87        downcoded = slug; 
     88    } 
     89    return downcoded; 
     90} 
     91 
     92 
    193function URLify(s, num_chars) { 
    294    // changes, e.g., "Petty theft" to "petty_theft" 
    395    // remove all these words from the string before urlifying 
     96    s = downcode(s); 
    497    removelist = ["a", "an", "as", "at", "before", "but", "by", "for", "from", 
    598                  "is", "in", "into", "like", "of", "off", "on", "onto", "per", 
     
    8101    r = new RegExp('\\b(' + removelist.join('|') + ')\\b', 'gi'); 
    9102    s = s.replace(r, ''); 
     103    // if downcode doesn't hit, the char will be stripped here 
    10104    s = s.replace(/[^-\w\s]/g, '');  // remove unneeded chars 
    11105    s = s.replace(/^\s+|\s+$/g, ''); // trim leading/trailing spaces 
     
    14108    return s.substring(0, num_chars);// trim to first num_chars chars 
    15109} 
     110 
  • django/trunk/django/contrib/admin/models.py

    r5519 r5609  
    22from django.contrib.contenttypes.models import ContentType 
    33from django.contrib.auth.models import User 
    4 from django.utils.translation import gettext_lazy as _ 
     4from django.utils.translation import ugettext_lazy as _ 
     5from django.utils.encoding import smart_unicode 
    56 
    67ADDITION = 1 
     
    1011class LogEntryManager(models.Manager): 
    1112    def log_action(self, user_id, content_type_id, object_id, object_repr, action_flag, change_message=''): 
    12         e = self.model(None, None, user_id, content_type_id, str(object_id), object_repr[:200], action_flag, change_message) 
     13        e = self.model(None, None, user_id, content_type_id, smart_unicode(object_id), object_repr[:200], action_flag, change_message) 
    1314        e.save() 
    1415 
     
    2930 
    3031    def __repr__(self): 
    31         return str(self.action_time) 
     32        return smart_unicode(self.action_time) 
    3233 
    3334    def is_addition(self): 
     
    4950        This is relative to the Django admin index page. 
    5051        """ 
    51         return "%s/%s/%s/" % (self.content_type.app_label, self.content_type.model, self.object_id) 
     52        return u"%s/%s/%s/" % (self.content_type.app_label, self.content_type.model, self.object_id) 
  • django/trunk/django/contrib/admin/templates/admin/filter.html

    r3349 r5609  
    44{% for choice in choices %} 
    55    <li{% if choice.selected %} class="selected"{% endif %}> 
    6     <a href="{{ choice.query_string }}">{{ choice.display|escape }}</a></li> 
     6    <a href="{{ choice.query_string|iriencode }}">{{ choice.display|escape }}</a></li> 
    77{% endfor %} 
    88</ul> 
  • django/trunk/django/contrib/admin/templatetags/adminapplist.py

    r5511 r5609  
    11from django import template 
    22from django.db.models import get_models 
     3from django.utils.encoding import force_unicode 
    34 
    45register = template.Library() 
     
    3738                        if True in perms.values(): 
    3839                            model_list.append({ 
    39                                 'name': capfirst(m._meta.verbose_name_plural), 
    40                                 'admin_url': '%s/%s/' % (app_label, m.__name__.lower()), 
     40                                'name': force_unicode(capfirst(m._meta.verbose_name_plural)), 
     41                                'admin_url': u'%s/%s/' % (force_unicode(app_label), m.__name__.lower()), 
    4142                                'perms': perms, 
    4243                            }) 
  • django/trunk/django/contrib/admin/templatetags/admin_list.py

    r5318 r5609  
    77from django.utils.html import escape 
    88from django.utils.text import capfirst 
    9 from django.utils.translation import get_date_formats, get_partial_date_formats 
     9from django.utils.translation import get_date_formats, get_partial_date_formats, ugettext as _ 
     10from django.utils.encoding import smart_unicode, smart_str, force_unicode 
    1011from django.template import Library 
    1112import datetime 
     
    1718def paginator_number(cl,i): 
    1819    if i == DOT: 
    19         return '... ' 
     20        return u'... ' 
    2021    elif i == cl.page_num: 
    21         return '<span class="this-page">%d</span> ' % (i+1) 
     22        return u'<span class="this-page">%d</span> ' % (i+1) 
    2223    else: 
    23         return '<a href="%s"%s>%d</a> ' % (cl.get_query_string({PAGE_VAR: i}), (i == cl.paginator.pages-1 and ' class="end"' or ''), i+1) 
     24        return u'<a href="%s"%s>%d</a> ' % (cl.get_query_string({PAGE_VAR: i}), (i == cl.paginator.pages-1 and ' class="end"' or ''), i+1) 
    2425paginator_number = register.simple_tag(paginator_number) 
    2526 
     
    7677        except models.FieldDoesNotExist: 
    7778            # For non-field list_display values, check for the function 
    78             # attribute "short_description". If that doesn't exist, fall 
    79             # back to the method name. And __str__ is a special-case. 
    80             if field_name == '__str__': 
    81                 header = lookup_opts.verbose_name 
     79            # attribute "short_description". If that doesn't exist, fall back 
     80            # to the method name. And __str__ and __unicode__ are special-cases. 
     81            if field_name == '__unicode__': 
     82                header = force_unicode(lookup_opts.verbose_name) 
     83            elif field_name == '__str__': 
     84                header = smart_str(lookup_opts.verbose_name) 
    8285            else: 
    8386                attr = getattr(cl.model, field_name) # Let AttributeErrors propagate. 
     
    115118def _boolean_icon(field_val): 
    116119    BOOLEAN_MAPPING = {True: 'yes', False: 'no', None: 'unknown'} 
    117     return '<img src="%simg/admin/icon-%s.gif" alt="%s" />' % (settings.ADMIN_MEDIA_PREFIX, BOOLEAN_MAPPING[field_val], field_val) 
     120    return u'<img src="%simg/admin/icon-%s.gif" alt="%s" />' % (settings.ADMIN_MEDIA_PREFIX, BOOLEAN_MAPPING[field_val], field_val) 
    118121 
    119122def items_for_result(cl, result): 
     
    137140                    result_repr = _boolean_icon(attr) 
    138141                else: 
    139                     result_repr = str(attr) 
     142                    result_repr = smart_unicode(attr) 
    140143            except (AttributeError, ObjectDoesNotExist): 
    141144                result_repr = EMPTY_CHANGELIST_VALUE 
     
    180183                result_repr = dict(f.choices).get(field_val, EMPTY_CHANGELIST_VALUE) 
    181184            else: 
    182                 result_repr = escape(str(field_val)
    183         if result_repr == '': 
     185                result_repr = escape(field_val
     186        if force_unicode(result_repr) == '': 
    184187            result_repr = '&nbsp;' 
    185188        # If list_display_links not defined, add the link tag to the first field 
    186         if (first and not cl.lookup_opts.admin.list_display_links) or field_name in cl.lookup_opts.admin.list_display_links:  
     189        if (first and not cl.lookup_opts.admin.list_display_links) or field_name in cl.lookup_opts.admin.list_display_links: 
    187190            table_tag = {True:'th', False:'td'}[first] 
    188191            first = False 
    189192            url = cl.url_for_result(result) 
    190             result_id = str(getattr(result, pk)) # str() is needed in case of 23L (long ints) 
    191             yield ('<%s%s><a href="%s"%s>%s</a></%s>' % \ 
     193            result_id = smart_unicode(getattr(result, pk)) # conversion to string is needed in case of 23L (long ints) 
     194            yield (u'<%s%s><a href="%s"%s>%s</a></%s>' % \ 
    192195                (table_tag, row_class, url, (cl.is_popup and ' onclick="opener.dismissRelatedLookupPopup(window, %r); return false;"' % result_id or ''), result_repr, table_tag)) 
    193196        else: 
    194             yield ('<td%s>%s</td>' % (row_class, result_repr)) 
     197            yield (u'<td%s>%s</td>' % (row_class, result_repr)) 
    195198 
    196199def results(cl): 
  • django/trunk/django/contrib/admin/templatetags/admin_modify.py

    r5511 r5609  
    33from django.template import loader 
    44from django.utils.text import capfirst 
     5from django.utils.encoding import force_unicode 
    56from django.db import models 
    67from django.db.models.fields import Field 
     
    1516 
    1617def class_name_to_underscored(name): 
    17     return '_'.join([s.lower() for s in word_re.findall(name)[:-1]]) 
     18    return u'_'.join([s.lower() for s in word_re.findall(name)[:-1]]) 
    1819 
    1920def include_admin_script(script_path): 
     
    3233    if not absolute_url_re.match(script_path): 
    3334        script_path = '%s%s' % (settings.ADMIN_MEDIA_PREFIX, script_path) 
    34     return '<script type="text/javascript" src="%s"></script>' % script_path 
     35    return u'<script type="text/javascript" src="%s"></script>' % script_path 
    3536include_admin_script = register.simple_tag(include_admin_script) 
    3637 
     
    6263            class_names.append('inline') 
    6364        colon = ":" 
    64     class_str = class_names and ' class="%s"' % ' '.join(class_names) or '' 
    65     return '<label for="%s"%s>%s%s</label> ' % (bound_field.element_id, class_str, \ 
    66         capfirst(bound_field.field.verbose_name), colon) 
     65    class_str = class_names and u' class="%s"' % u' '.join(class_names) or u'' 
     66    return u'<label for="%s"%s>%s%s</label> ' % (bound_field.element_id, class_str, \ 
     67        force_unicode(capfirst(bound_field.field.verbose_name)), colon) 
    6768field_label = register.simple_tag(field_label) 
    6869 
     
    7879            try: 
    7980                field_class_name = klass.__name__ 
    80                 template_name = "widget/%s.html" % class_name_to_underscored(field_class_name) 
     81                template_name = u"widget/%s.html" % class_name_to_underscored(field_class_name) 
    8182                nodelist = loader.get_template(template_name).nodelist 
    8283            except template.TemplateDoesNotExist: 
     
    176177 
    177178def output_all(form_fields): 
    178     return ''.join([str(f) for f in form_fields]) 
     179    return u''.join([force_unicode(f) for f in form_fields]) 
    179180output_all = register.simple_tag(output_all) 
    180181 
     
    183184    for field in auto_pop_fields: 
    184185        if change: 
    185             t.append('document.getElementById("id_%s")._changed = true;' % field.name) 
     186            t.append(u'document.getElementById("id_%s")._changed = true;' % field.name) 
    186187        else: 
    187             t.append('document.getElementById("id_%s").onchange = function() { this._changed = true; };' % field.name) 
    188  
    189         add_values = ' + " " + '.join(['document.getElementById("id_%s").value' % g for g in field.prepopulate_from]) 
     188            t.append(u'document.getElementById("id_%s").onchange = function() { this._changed = true; };' % field.name) 
     189 
     190        add_values = u' + " " + '.join([u'document.getElementById("id_%s").value' % g for g in field.prepopulate_from]) 
    190191        for f in field.prepopulate_from: 
    191             t.append('document.getElementById("id_%s").onkeyup = function() {' \ 
     192            t.append(u'document.getElementById("id_%s").onkeyup = function() {' \ 
    192193                     ' var e = document.getElementById("id_%s");' \ 
    193194                     ' if(!e._changed) { e.value = URLify(%s, %s);} }; ' % ( 
    194195                     f, field.name, add_values, field.maxlength)) 
    195     return ''.join(t) 
     196    return u''.join(t) 
    196197auto_populated_field_script = register.simple_tag(auto_populated_field_script) 
    197198 
     
    199200    f = bound_field.field 
    200201    if f.rel and isinstance(f.rel, models.ManyToManyRel) and f.rel.filter_interface: 
    201         return '<script type="text/javascript">addEvent(window, "load", function(e) {' \ 
     202        return u'<script type="text/javascript">addEvent(window, "load", function(e) {' \ 
    202203              ' SelectFilter.init("id_%s", "%s", %s, "%s"); });</script>\n' % ( 
    203204              f.name, f.verbose_name.replace('"', '\\"'), f.rel.filter_interface-1, settings.ADMIN_MEDIA_PREFIX) 
  • django/trunk/django/contrib/admin/views/auth.py

    r5091 r5609  
    77from django.http import HttpResponseRedirect 
    88from django.utils.html import escape 
     9from django.utils.translation import ugettext as _ 
    910 
    1011def user_add_stage(request): 
  • django/trunk/django/contrib/admin/views/decorators.py

    r5091 r5609  
    44from django.contrib.auth import authenticate, login 
    55from django.shortcuts import render_to_response 
    6 from django.utils.translation import gettext_lazy 
     6from django.utils.translation import ugettext_lazy, ugettext as _ 
    77import base64, datetime, md5 
    88import cPickle as pickle 
    99 
    10 ERROR_MESSAGE = gettext_lazy("Please enter a correct username and password. Note that both fields are case-sensitive.") 
     10ERROR_MESSAGE = ugettext_lazy("Please enter a correct username and password. Note that both fields are case-sensitive.") 
    1111LOGIN_FORM_KEY = 'this_is_the_login_form' 
    1212 
  • django/trunk/django/contrib/admin/views/doc.py

    r5302 r5609  
    1010from django.contrib.admin import utils 
    1111from django.contrib.sites.models import Site 
     12from django.utils.translation import ugettext as _ 
    1213import inspect, os, re 
    1314 
  • django/trunk/django/contrib/admin/views/main.py

    r5514 r5609  
    1313from django.utils.html import escape 
    1414from django.utils.text import capfirst, get_text_list 
     15from django.utils.encoding import force_unicode, smart_str 
     16from django.utils.translation import ugettext as _ 
    1517import operator 
    1618 
     
    131133            classes.append('error') 
    132134        if classes: 
    133             self.cell_class_attribute = ' class="%s" ' % ' '.join(classes) 
     135            self.cell_class_attribute = u' class="%s" ' % ' '.join(classes) 
    134136        self._repr_filled = False 
    135137 
    136138        if field.rel: 
    137             self.related_url = '../../../%s/%s/' % (field.rel.to._meta.app_label, field.rel.to._meta.object_name.lower()) 
     139            self.related_url = u'../../../%s/%s/' % (field.rel.to._meta.app_label, field.rel.to._meta.object_name.lower()) 
    138140 
    139141    def original_value(self): 
     
    146148        except AttributeError: 
    147149            if isinstance(self.field.rel, models.ManyToOneRel): 
    148                 self._display = getattr(self.original, self.field.name) 
     150                self._display = force_unicode(getattr(self.original, self.field.name), strings_only=True) 
    149151            elif isinstance(self.field.rel, models.ManyToManyRel): 
    150                 self._display = ", ".join([str(obj) for obj in getattr(self.original, self.field.name).all()]) 
     152                self._display = u", ".join([force_unicode(obj) for obj in getattr(self.original, self.field.name).all()]) 
    151153            return self._display 
    152154 
     
    259261            new_object = manipulator.save(new_data) 
    260262            pk_value = new_object._get_pk_val() 
    261             LogEntry.objects.log_action(request.user.id, ContentType.objects.get_for_model(model).id, pk_value, str(new_object), ADDITION) 
    262             msg = _('The %(name)s "%(obj)s" was added successfully.') % {'name': opts.verbose_name, 'obj': new_object} 
     263            LogEntry.objects.log_action(request.user.id, ContentType.objects.get_for_model(model).id, pk_value, force_unicode(new_object), ADDITION) 
     264            msg = _('The %(name)s "%(obj)s" was added successfully.') % {'name': force_unicode(opts.verbose_name), 'obj': new_object} 
    263265            # Here, we distinguish between different save types by checking for 
    264266            # the presence of keys in request.POST. 
     
    272274                    pk_value = '"%s"' % pk_value.replace('"', '\\"') 
    273275                return HttpResponse('<script type="text/javascript">opener.dismissAddAnotherPopup(window, %s, "%s");</script>' % \ 
    274                     (pk_value, str(new_object).replace('"', '\\"'))) 
     276                    (pk_value, force_unicode(new_object).replace('"', '\\"'))) 
    275277            elif "_addanother" in request.POST: 
    276                 request.user.message_set.create(message=msg + ' ' + (_("You may add another %s below.") % opts.verbose_name)) 
     278                request.user.message_set.create(message=msg + ' ' + (_("You may add another %s below.") % force_unicode(opts.verbose_name))) 
    277279                return HttpResponseRedirect(request.path) 
    278280            else: 
     
    292294 
    293295    c = template.RequestContext(request, { 
    294         'title': _('Add %s') % opts.verbose_name
     296        'title': _('Add %s') % force_unicode(opts.verbose_name)
    295297        'form': form, 
    296298        'is_popup': '_popup' in request.REQUEST, 
     
    346348            if not change_message: 
    347349                change_message = _('No fields changed.') 
    348             LogEntry.objects.log_action(request.user.id, ContentType.objects.get_for_model(model).id, pk_value, str(new_object), CHANGE, change_message) 
    349  
    350             msg = _('The %(name)s "%(obj)s" was changed successfully.') % {'name': opts.verbose_name, 'obj': new_object} 
     350            LogEntry.objects.log_action(request.user.id, ContentType.objects.get_for_model(model).id, pk_value, force_unicode(new_object), CHANGE, change_message) 
     351 
     352            msg = _('The %(name)s "%(obj)s" was changed successfully.') % {'name': force_unicode(opts.verbose_name), 'obj': new_object} 
    351353            if "_continue" in request.POST: 
    352354                request.user.message_set.create(message=msg + ' ' + _("You may edit it again below.")) 
     
    356358                    return HttpResponseRedirect(request.path) 
    357359            elif "_saveasnew" in request.POST: 
    358                 request.user.message_set.create(message=_('The %(name)s "%(obj)s" was added successfully. You may edit it again below.') % {'name': opts.verbose_name, 'obj': new_object}) 
     360                request.user.message_set.create(message=_('The %(name)s "%(obj)s" was added successfully. You may edit it again below.') % {'name': force_unicode(opts.verbose_name), 'obj': new_object}) 
    359361                return HttpResponseRedirect("../%s/" % pk_value) 
    360362            elif "_addanother" in request.POST: 
    361                 request.user.message_set.create(message=msg + ' ' + (_("You may add another %s below.") % opts.verbose_name)) 
     363                request.user.message_set.create(message=msg + ' ' + (_("You may add another %s below.") % force_unicode(opts.verbose_name))) 
    362364                return HttpResponseRedirect("../add/") 
    363365            else: 
     
    394396 
    395397    c = template.RequestContext(request, { 
    396         'title': _('Change %s') % opts.verbose_name
     398        'title': _('Change %s') % force_unicode(opts.verbose_name)
    397399        'form': form, 
    398400        'object_id': object_id, 
     
    435437                    # Don't display link to edit, because it either has no 
    436438                    # admin or is edited inline. 
    437                     nh(deleted_objects, current_depth, ['%s: %s' % (capfirst(related.opts.verbose_name), sub_obj), []]) 
     439                    nh(deleted_objects, current_depth, [u'%s: %s' % (force_unicode(capfirst(related.opts.verbose_name)), sub_obj), []]) 
    438440                else: 
    439441                    # Display a link to the admin page. 
    440                     nh(deleted_objects, current_depth, ['%s: <a href="../../../../%s/%s/%s/">%s</a>' % \ 
    441                         (capfirst(related.opts.verbose_name), related.opts.app_label, related.opts.object_name.lower(), 
     442                    nh(deleted_objects, current_depth, [u'%s: <a href="../../../../%s/%s/%s/">%s</a>' % \ 
     443                        (force_unicode(capfirst(related.opts.verbose_name)), related.opts.app_label, related.opts.object_name.lower(), 
    442444                        sub_obj._get_pk_val(), sub_obj), []]) 
    443445                _get_deleted_objects(deleted_objects, perms_needed, user, sub_obj, related.opts, current_depth+2) 
     
    449451                    # Don't display link to edit, because it either has no 
    450452                    # admin or is edited inline. 
    451                     nh(deleted_objects, current_depth, ['%s: %s' % (capfirst(related.opts.verbose_name), escape(str(sub_obj))), []]) 
     453                    nh(deleted_objects, current_depth, [u'%s: %s' % (force_unicode(capfirst(related.opts.verbose_name)), escape(sub_obj)), []]) 
    452454                else: 
    453455                    # Display a link to the admin page. 
    454                     nh(deleted_objects, current_depth, ['%s: <a href="../../../../%s/%s/%s/">%s</a>' % \ 
    455                         (capfirst(related.opts.verbose_name), related.opts.app_label, related.opts.object_name.lower(), sub_obj._get_pk_val(), escape(str(sub_obj))), []]) 
     456                    nh(deleted_objects, current_depth, [u'%s: <a href="../../../../%s/%s/%s/">%s</a>' % \ 
     457                        (force_unicode(capfirst(related.opts.verbose_name)), related.opts.app_label, related.opts.object_name.lower(), sub_obj._get_pk_val(), escape(sub_obj)), []]) 
    456458                _get_deleted_objects(deleted_objects, perms_needed, user, sub_obj, related.opts, current_depth+2) 
    457459            # If there were related objects, and the user doesn't have 
     
    467469        rel_opts_name = related.get_accessor_name() 
    468470        has_related_objs = False 
    469         
     471 
    470472        # related.get_accessor_name() could return None for symmetrical relationships 
    471473        if rel_opts_name: 
     
    480482                    # admin or is edited inline. 
    481483                    nh(deleted_objects, current_depth, [_('One or more %(fieldname)s in %(name)s: %(obj)s') % \ 
    482                         {'fieldname': related.field.verbose_name, 'name': related.opts.verbose_name, 'obj': escape(str(sub_obj))}, []]) 
     484                        {'fieldname': force_unicode(related.field.verbose_name), 'name': force_unicode(related.opts.verbose_name), 'obj': escape(sub_obj)}, []]) 
    483485                else: 
    484486                    # Display a link to the admin page. 
    485487                    nh(deleted_objects, current_depth, [ 
    486                         (_('One or more %(fieldname)s in %(name)s:') % {'fieldname': related.field.verbose_name, 'name':related.opts.verbose_name}) + \ 
    487                         (' <a href="../../../../%s/%s/%s/">%s</a>' % \ 
    488                             (related.opts.app_label, related.opts.module_name, sub_obj._get_pk_val(), escape(str(sub_obj)))), []]) 
     488                        (_('One or more %(fieldname)s in %(name)s:') % {'fieldname': force_unicode(related.field.verbose_name), 'name': force_unicode(related.opts.verbose_name)}) + \ 
     489                        (u' <a href="../../../../%s/%s/%s/">%s</a>' % \ 
     490                            (related.opts.app_label, related.opts.module_name, sub_obj._get_pk_val(), escape(sub_obj))), []]) 
    489491        # If there were related objects, and the user doesn't have 
    490492        # permission to change them, add the missing perm to perms_needed. 
    491493        if related.opts.admin and has_related_objs: 
    492             p = '%s.%s' % (related.opts.app_label, related.opts.get_change_permission()) 
     494            p = u'%s.%s' % (related.opts.app_label, related.opts.get_change_permission()) 
    493495            if not user.has_perm(p): 
    494496                perms_needed.add(related.opts.verbose_name) 
     
    506508    # Populate deleted_objects, a data structure of all related objects that 
    507509    # will also be deleted. 
    508     deleted_objects = ['%s: <a href="../../%s/">%s</a>' % (capfirst(opts.verbose_name), object_id, escape(str(obj))), []] 
     510    deleted_objects = [u'%s: <a href="../../%s/">%s</a>' % (force_unicode(capfirst(opts.verbose_name)), force_unicode(object_id), escape(obj)), []] 
    509511    perms_needed = set() 
    510512    _get_deleted_objects(deleted_objects, perms_needed, request.user, obj, opts, 1) 
     
    513515        if perms_needed: 
    514516            raise PermissionDenied 
    515         obj_display = str(obj) 
     517        obj_display = force_unicode(obj) 
    516518        obj.delete() 
    517519        LogEntry.objects.log_action(request.user.id, ContentType.objects.get_for_model(model).id, object_id, obj_display, DELETION) 
    518         request.user.message_set.create(message=_('The %(name)s "%(obj)s" was deleted successfully.') % {'name': opts.verbose_name, 'obj': obj_display}) 
     520        request.user.message_set.create(message=_('The %(name)s "%(obj)s" was deleted successfully.') % {'name': force_unicode(opts.verbose_name), 'obj': obj_display}) 
    519521        return HttpResponseRedirect("../../") 
    520522    extra_context = { 
    521523        "title": _("Are you sure?"), 
    522         "object_name": opts.verbose_name
     524        "object_name": force_unicode(opts.verbose_name)
    523525        "object": obj, 
    524526        "deleted_objects": deleted_objects, 
     
    543545        'title': _('Change history: %s') % obj, 
    544546        'action_list': action_list, 
    545         'module_name': capfirst(model._meta.verbose_name_plural), 
     547        'module_name': force_unicode(capfirst(model._meta.verbose_name_plural)), 
    546548        'object': obj, 
    547549    } 
     
    575577        self.query_set = self.get_query_set() 
    576578        self.get_results(request) 
    577         self.title = (self.is_popup and _('Select %s') % self.opts.verbose_name or _('Select %s to change') % self.opts.verbose_name
     579        self.title = (self.is_popup and _('Select %s') % force_unicode(self.opts.verbose_name) or _('Select %s to change') % force_unicode(self.opts.verbose_name)
    578580        self.filter_specs, self.has_filters = self.get_filters(request) 
    579581        self.pk_attname = self.lookup_opts.pk.attname 
     
    603605            elif v is not None: 
    604606                p[k] = v 
    605         return '?' + '&amp;'.join(['%s=%s' % (k, v) for k, v in p.items()]).replace(' ', '%20') 
     607        return '?' + '&amp;'.join([u'%s=%s' % (k, v) for k, v in p.items()]).replace(' ', '%20') 
    606608 
    607609    def get_results(self, request): 
     
    689691            if i in lookup_params: 
    690692                del lookup_params[i] 
     693        for key, value in lookup_params.items(): 
     694            if not isinstance(key, str): 
     695                # 'key' will be used as a keyword argument later, so Python 
     696                # requires it to be a string. 
     697                del lookup_params[key] 
     698                lookup_params[smart_str(key)] = value 
    691699 
    692700        # Apply lookup parameters from the query string. 
  • django/trunk/django/contrib/auth/forms.py

    r5493 r5609  
    55from django.core import validators 
    66from django import oldforms 
    7 from django.utils.translation import gettext as _ 
     7from django.utils.translation import ugettext as _ 
    88 
    99class UserCreationForm(oldforms.Manipulator): 
  • django/trunk/django/contrib/auth/management.py

    r4265 r5609  
    88 
    99def _get_permission_codename(action, opts): 
    10     return '%s_%s' % (action, opts.object_name.lower()) 
     10    return u'%s_%s' % (action, opts.object_name.lower()) 
    1111 
    1212def _get_all_permissions(opts): 
     
    1414    perms = [] 
    1515    for action in ('add', 'change', 'delete'): 
    16         perms.append((_get_permission_codename(action, opts), 'Can %s %s' % (action, opts.verbose_name))) 
     16        perms.append((_get_permission_codename(action, opts), u'Can %s %s' % (action, opts.verbose_name_raw))) 
    1717    return perms + list(opts.permissions) 
    1818 
  • django/trunk/django/contrib/auth/models.py

    r5590 r5609  
    33from django.db import backend, connection, models 
    44from django.contrib.contenttypes.models import ContentType 
    5 from django.utils.translation import gettext_lazy as _ 
     5from django.utils.encoding import smart_str 
     6from django.utils.translation import ugettext_lazy as _ 
    67import datetime 
     8import urllib 
    79 
    810try: 
     
    1921    if algo == 'md5': 
    2022        import md5 
    21         return hsh == md5.new(salt+raw_password).hexdigest() 
     23        return hsh == md5.new(smart_str(salt + raw_password)).hexdigest() 
    2224    elif algo == 'sha1': 
    2325        import sha 
    24         return hsh == sha.new(salt+raw_password).hexdigest() 
     26        return hsh == sha.new(smart_str(salt + raw_password)).hexdigest() 
    2527    elif algo == 'crypt': 
    2628        try: 
     
    2830        except ImportError: 
    2931            raise ValueError, "Crypt password algorithm not supported in this environment." 
    30         return hsh == crypt.crypt(raw_password, salt
     32        return hsh == crypt.crypt(smart_str(raw_password), smart_str(salt)
    3133    raise ValueError, "Got unknown password algorithm type in password." 
    3234 
     
    5759        ordering = ('content_type', 'codename') 
    5860 
    59     def __str__(self): 
    60         return "%s | %s | %s" % (self.content_type.app_label, self.content_type, self.name) 
     61    def __unicode__(self): 
     62        return u"%s | %s | %s" % (self.content_type.app_label, self.content_type, self.name) 
    6163 
    6264class Group(models.Model): 
     
    7880        search_fields = ('name',) 
    7981 
    80     def __str__(self): 
     82    def __unicode__(self): 
    8183        return self.name 
    8284 
     
    134136        search_fields = ('username', 'first_name', 'last_name', 'email') 
    135137 
    136     def __str__(self): 
     138    def __unicode__(self): 
    137139        return self.username 
    138140 
    139141    def get_absolute_url(self): 
    140         return "/users/%s/" % self.username 
     142        return "/users/%s/" % urllib.quote(smart_str(self.username)) 
    141143 
    142144    def is_anonymous(self): 
     
    151153    def get_full_name(self): 
    152154        "Returns the first_name plus the last_name, with a space in between." 
    153         full_name = '%s %s' % (self.first_name, self.last_name) 
     155        full_name = u'%s %s' % (self.first_name, self.last_name) 
    154156        return full_name.strip() 
    155157 
     
    158160        algo = 'sha1' 
    159161        salt = sha.new(str(random.random())).hexdigest()[:5] 
    160         hsh = sha.new(salt+raw_password).hexdigest() 
     162        hsh = sha.new(salt + smart_str(raw_password)).hexdigest() 
    161163        self.password = '%s$%s$%s' % (algo, salt, hsh) 
    162164 
     
    170172        if '$' not in self.password: 
    171173            import md5 
    172             is_correct = (self.password == md5.new(raw_password).hexdigest()) 
     174            is_correct = (self.password == md5.new(smart_str(raw_password)).hexdigest()) 
    173175            if is_correct: 
    174176                # Convert the password to the new, more secure format. 
     
    210212    def get_all_permissions(self): 
    211213        if not hasattr(self, '_perm_cache'): 
    212             self._perm_cache = set(["%s.%s" % (p.content_type.app_label, p.codename) for p in self.user_permissions.select_related()]) 
     214            self._perm_cache = set([u"%s.%s" % (p.content_type.app_label, p.codename) for p in self.user_permissions.select_related()]) 
    213215            self._perm_cache.update(self.get_group_permissions()) 
    214216        return self._perm_cache 
     
    272274    message = models.TextField(_('message')) 
    273275 
    274     def __str__(self): 
     276    def __unicode__(self): 
    275277        return self.message 
    276278 
     
    282284        pass 
    283285 
     286    def __unicode__(self): 
     287        return 'AnonymousUser' 
     288 
    284289    def __str__(self): 
    285         return 'AnonymousUser' 
     290        return unicode(self).encode('utf-8') 
    286291 
    287292    def __eq__(self, other): 
  • django/trunk/django/contrib/auth/views.py

    r5072 r5609  
    88from django.contrib.auth.decorators import login_required 
    99from django.contrib.auth import REDIRECT_FIELD_NAME 
     10from django.utils.translation import ugettext as _ 
    1011 
    1112def login(request, template_name='registration/login.html'): 
  • django/trunk/django/contrib/comments/feeds.py

    r5408 r5609  
    1212        if not hasattr(self, '_site'): 
    1313            self._site = Site.objects.get_current() 
    14         return "%s comments" % self._site.name 
     14        return u"%s comments" % self._site.name 
    1515 
    1616    def link(self): 
     
    2222        if not hasattr(self, '_site'): 
    2323            self._site = Site.objects.get_current() 
    24         return "Latest comments on %s" % self._site.name 
     24        return u"Latest comments on %s" % self._site.name 
    2525 
    2626    def get_query_set(self): 
  • django/trunk/django/contrib/comments/models.py

    r4873 r5609  
    33from django.contrib.sites.models import Site 
    44from django.contrib.auth.models import User 
    5 from django.utils.translation import gettext_lazy as _ 
     5from django.utils.translation import ugettext_lazy as _ 
    66from django.conf import settings 
    77import datetime 
  • django/trunk/django/contrib/comments/views/comments.py

    r5091 r5609  
    1212from django.utils.text import normalize_newlines 
    1313from django.conf import settings 
    14 from django.utils.translation import ngettext 
     14from django.utils.translation import ungettext, ugettext as _ 
     15from django.utils.encoding import smart_unicode 
    1516import base64, datetime 
    1617 
     
    109110        # send the comment to the managers. 
    110111        if self.user_cache.comment_set.count() <= settings.COMMENTS_FIRST_FEW: 
    111             message = ngettext('This comment was posted by a user who has posted fewer than %(count)s comment:\n\n%(text)s', 
     112            message = ungettext('This comment was posted by a user who has posted fewer than %(count)s comment:\n\n%(text)s', 
    112113                'This comment was posted by a user who has posted fewer than %(count)s comments:\n\n%(text)s', settings.COMMENTS_FIRST_FEW) % \ 
    113114                {'count': settings.COMMENTS_FIRST_FEW, 'text': c.get_as_text()} 
     
    249250        # serve up the "Thanks for posting" page as if the comment WAS posted. 
    250251        if request.META['REMOTE_ADDR'] in settings.BANNED_IPS: 
    251             mail_admins("Banned IP attempted to post comment", str(request.POST) + "\n\n" + str(request.META)) 
     252            mail_admins("Banned IP attempted to post comment", smart_unicode(request.POST) + "\n\n" + str(request.META)) 
    252253        else: 
    253254            manipulator.do_html2python(new_data) 
     
    313314        if request.META['REMOTE_ADDR'] in settings.BANNED_IPS: 
    314315            from django.core.mail import mail_admins 
    315             mail_admins("Practical joker", str(request.POST) + "\n\n" + str(request.META)) 
     316            mail_admins("Practical joker", smart_unicode(request.POST) + "\n\n" + str(request.META)) 
    316317        else: 
    317318            manipulator.do_html2python(new_data) 
  • django/trunk/django/contrib/comments/views/karma.py

    r4486 r5609  
    33from django.template import RequestContext 
    44from django.contrib.comments.models import Comment, KarmaScore 
     5from django.utils.translation import ugettext as _ 
    56 
    67def vote(request, comment_id, vote): 
  • django/trunk/django/contrib/contenttypes/generic.py

    r5172 r5609  
    5050    def __get__(self, instance, instance_type=None): 
    5151        if instance is None: 
    52             raise AttributeError, "%s must be accessed via instance" % self.name 
     52            raise AttributeError, u"%s must be accessed via instance" % self.name 
    5353 
    5454        try: 
     
    6767    def __set__(self, instance, value): 
    6868        if instance is None: 
    69             raise AttributeError, "%s must be accessed via instance" % self.related.opts.object_name 
     69            raise AttributeError, u"%s must be accessed via instance" % self.related.opts.object_name 
    7070 
    7171        ct = None 
  • django/trunk/django/contrib/contenttypes/management.py

    r4703 r5609  
    55from django.dispatch import dispatcher 
    66from django.db.models import get_apps, get_models, signals 
     7from django.utils.encoding import smart_unicode 
    78 
    89def create_contenttypes(app, created_models, verbosity=2): 
     
    1819                model=opts.object_name.lower()) 
    1920        except ContentType.DoesNotExist: 
    20             ct = ContentType(name=str(opts.verbose_name), 
     21            ct = ContentType(name=smart_unicode(opts.verbose_name_raw), 
    2122                app_label=opts.app_label, model=opts.object_name.lower()) 
    2223            ct.save() 
  • django/trunk/django/contrib/contenttypes/models.py

    r4703 r5609  
    11from django.db import models 
    2 from django.utils.translation import gettext_lazy as _ 
     2from django.utils.translation import ugettext_lazy as _ 
     3from django.utils.encoding import smart_unicode 
    34 
    45CONTENT_TYPE_CACHE = {} 
     
    1415            ct = CONTENT_TYPE_CACHE[key] 
    1516        except KeyError: 
    16             # The str() is needed around opts.verbose_name because it's a 
    17             # django.utils.functional.__proxy__ object. 
     17            # The smart_unicode() is needed around opts.verbose_name_raw because it might 
     18            # be a django.utils.functional.__proxy__ object. 
    1819            ct, created = self.model._default_manager.get_or_create(app_label=key[0], 
    19                 model=key[1], defaults={'name': str(opts.verbose_name)}) 
     20                model=key[1], defaults={'name': smart_unicode(opts.verbose_name_raw)}) 
    2021            CONTENT_TYPE_CACHE[key] = ct 
    2122        return ct 
    22          
     23 
    2324    def clear_cache(self): 
    2425        """ 
     
    4344        unique_together = (('app_label', 'model'),) 
    4445 
    45     def __str__(self): 
     46    def __unicode__(self): 
    4647        return self.name 
    4748 
  • django/trunk/django/contrib/databrowse/datastructures.py

    r5016 r5609  
    88from django.utils.text import capfirst 
    99from django.utils.translation import get_date_formats 
     10from django.utils.encoding import smart_unicode, smart_str, iri_to_uri 
    1011 
    1112EMPTY_VALUE = '(None)' 
     
    2021 
    2122    def __repr__(self): 
    22         return '<EasyModel for %s>' % self.model._meta.object_name 
     23        return '<EasyModel for %s>' % smart_str(self.model._meta.object_name) 
    2324 
    2425    def model_databrowse(self): 
     
    5556 
    5657    def __repr__(self): 
    57         return '<EasyField for %s.%s>' % (self.model.model._meta.object_name, self.field.name
     58        return smart_str(u'<EasyField for %s.%s>' % (self.model.model._meta.object_name, self.field.name)
    5859 
    5960    def choices(self): 
     
    7374 
    7475    def __repr__(self): 
    75         return '<EasyChoice for %s.%s>' % (self.model.model._meta.object_name, self.field.name
     76        return smart_str(u'<EasyChoice for %s.%s>' % (self.model.model._meta.object_name, self.field.name)
    7677 
    7778    def url(self): 
    78         return '%s%s/%s/%s/%s/' % (self.model.site.root_url, self.model.model._meta.app_label, self.model.model._meta.module_name, self.field.field.name, self.value
     79        return '%s%s/%s/%s/%s/' % (self.model.site.root_url, self.model.model._meta.app_label, self.model.model._meta.module_name, self.field.field.name, iri_to_uri(self.value)
    7980 
    8081class EasyInstance(object): 
     
    8384 
    8485    def __repr__(self): 
    85         return '<EasyInstance for %s (%s)>' % (self.model.model._meta.object_name, self.instance._get_pk_val()) 
     86        return smart_str(u'<EasyInstance for %s (%s)>' % (self.model.model._meta.object_name, self.instance._get_pk_val())) 
     87 
     88    def __unicode__(self): 
     89        val = smart_unicode(self.instance) 
     90        if len(val) > 30: 
     91            return val[:30] + u'...' 
     92        return val 
    8693 
    8794    def __str__(self): 
    88         val = str(self.instance) 
    89         if len(val) > 30: 
    90             return val[:30] + '...' 
    91         return val 
     95        return self.__unicode__().encode('utf-8') 
    9296 
    9397    def pk(self): 
     
    9599 
    96100    def url(self): 
    97         return '%s%s/%s/objects/%s/' % (self.model.site.root_url, self.model.model._meta.app_label, self.model.model._meta.module_name, self.pk()) 
     101        return '%s%s/%s/objects/%s/' % (self.model.site.root_url, self.model.model._meta.app_label, self.model.model._meta.module_name, iri_to_uri(self.pk())) 
    98102 
    99103    def fields(self): 
     
    127131 
    128132    def __repr__(self): 
    129         return '<EasyInstanceField for %s.%s>' % (self.model.model._meta.object_name, self.field.name
     133        return smart_str(u'<EasyInstanceField for %s.%s>' % (self.model.model._meta.object_name, self.field.name)
    130134 
    131135    def values(self): 
     
    176180                lst = [] 
    177181                for value in self.values(): 
    178                     url = '%s%s/%s/objects/%s/' % (self.model.site.root_url, m.model._meta.app_label, m.model._meta.module_name, value._get_pk_val()) 
    179                     lst.append((str(value), url)) 
     182                    url = '%s%s/%s/objects/%s/' % (self.model.site.root_url, m.model._meta.app_label, m.model._meta.module_name, iri_to_uri(value._get_pk_val())) 
     183                    lst.append((smart_unicode(value), url)) 
    180184            else: 
    181185                lst = [(value, None) for value in self.values()] 
     
    183187            lst = [] 
    184188            for value in self.values(): 
    185                 url = '%s%s/%s/fields/%s/%s/' % (self.model.site.root_url, self.model.model._meta.app_label, self.model.model._meta.module_name, self.field.name, self.raw_value
     189                url = '%s%s/%s/fields/%s/%s/' % (self.model.site.root_url, self.model.model._meta.app_label, self.model.model._meta.module_name, self.field.name, iri_to_uri(self.raw_value)
    186190                lst.append((value, url)) 
    187191        elif isinstance(self.field, models.URLField): 
    188192            val = self.values()[0] 
    189             lst = [(val, val)] 
     193            lst = [(val, iri_to_uri(val))] 
    190194        else: 
    191195            lst = [(self.values()[0], None)] 
  • django/trunk/django/contrib/databrowse/plugins/calendars.py

    r5011 r5609  
    77from django.utils.translation import get_date_formats 
    88from django.views.generic import date_based 
     9from django.utils.encoding import force_unicode 
    910import datetime 
    1011import time 
     
    2829        fields = self.field_dict(model) 
    2930        if not fields: 
    30             return '' 
    31         return '<p class="filter"><strong>View calendar by:</strong> %s</p>' % \ 
    32             ', '.join(['<a href="calendars/%s/">%s</a>' % (f.name, capfirst(f.verbose_name)) for f in fields.values()]) 
     31            return u'' 
     32        return u'<p class="filter"><strong>View calendar by:</strong> %s</p>' % \ 
     33            u', '.join(['<a href="calendars/%s/">%s</a>' % (f.name, force_unicode(capfirst(f.verbose_name))) for f in fields.values()]) 
    3334 
    3435    def urls(self, plugin_name, easy_instance_field): 
    3536        if isinstance(easy_instance_field.field, models.DateField): 
    36             return ['%s%s/%s/%s/%s/%s/' % (easy_instance_field.model.url(), 
     37            return [u'%s%s/%s/%s/%s/%s/' % (easy_instance_field.model.url(), 
    3738                plugin_name, easy_instance_field.field.name, 
    3839                easy_instance_field.raw_value.year, 
  • django/trunk/django/contrib/databrowse/plugins/fieldchoices.py

    r5011 r5609  
    55from django.shortcuts import render_to_response 
    66from django.utils.text import capfirst 
     7from django.utils.encoding import smart_str, force_unicode 
    78from django.views.generic import date_based 
    89import datetime 
    910import time 
     11import urllib 
    1012 
    1113class FieldChoicePlugin(DatabrowsePlugin): 
     
    3032        fields = self.field_dict(model) 
    3133        if not fields: 
    32             return '' 
    33         return '<p class="filter"><strong>View by:</strong> %s</p>' % \ 
    34             ', '.join(['<a href="fields/%s/">%s</a>' % (f.name, capfirst(f.verbose_name)) for f in fields.values()]) 
     34            return u'' 
     35        return u'<p class="filter"><strong>View by:</strong> %s</p>' % \ 
     36            u', '.join(['<a href="fields/%s/">%s</a>' % (f.name, force_unicode(capfirst(f.verbose_name))) for f in fields.values()]) 
    3537 
    3638    def urls(self, plugin_name, easy_instance_field): 
    3739        if easy_instance_field.field in self.field_dict(easy_instance_field.model.model).values(): 
    38             return ['%s%s/%s/%s/' % (easy_instance_field.model.url(), 
     40            return [u'%s%s/%s/%s/' % (easy_instance_field.model.url(), 
    3941                plugin_name, easy_instance_field.field.name, 
    40                 easy_instance_field.raw_value)] 
     42                urllib.quote(smart_str(easy_instance_field.raw_value)))] 
    4143 
    4244    def model_view(self, request, model_databrowse, url): 
  • django/trunk/django/contrib/databrowse/sites.py

    r5011 r5609  
    6161    def main_view(self, request): 
    6262        easy_model = EasyModel(self.site, self.model) 
    63         html_snippets = '\n'.join([p.model_index_html(request, self.model, self.site) for p in self.plugins.values()]) 
     63        html_snippets = u'\n'.join([p.model_index_html(request, self.model, self.site) for p in self.plugins.values()]) 
    6464        return render_to_response('databrowse/model_detail.html', { 
    6565            'model': easy_model, 
  • django/trunk/django/contrib/databrowse/templates/databrowse/fieldchoice_list.html

    r5011 r5609  
    1111<ul class="objectlist"> 
    1212{% for object in object_list %} 
    13 <li class="{% cycle odd,even %}"><a href="{{ object }}/">{{ object|escape }}</a></li> 
     13<li class="{% cycle odd,even %}"><a href="{{ object|iriencode }}/">{{ object|escape }}</a></li> 
    1414{% endfor %} 
    1515</ul> 
  • django/trunk/django/contrib/flatpages/models.py

    r4849 r5609  
    22from django.db import models 
    33from django.contrib.sites.models import Site 
    4 from django.utils.translation import gettext_lazy as _ 
     4from django.utils.translation import ugettext_lazy as _ 
    55 
    66class FlatPage(models.Model): 
     
    2727        search_fields = ('url', 'title') 
    2828 
    29     def __str__(self): 
    30         return "%s -- %s" % (self.url, self.title) 
     29    def __unicode__(self): 
     30        return u"%s -- %s" % (self.url, self.title) 
    3131 
    3232    def get_absolute_url(self): 
  • django/trunk/django/contrib/humanize/templatetags/humanize.py

    r4856 r5609  
    1 from django.utils.translation import ngettext 
    2 from django.utils.translation import gettext_lazy as _ 
     1from django.utils.translation import ungettext, ugettext as _ 
     2from django.utils.encoding import force_unicode 
    33from django import template 
    44import re 
     
    1717    t = (_('th'), _('st'), _('nd'), _('rd'), _('th'), _('th'), _('th'), _('th'), _('th'), _('th')) 
    1818    if value % 100 in (11, 12, 13): # special case 
    19         return "%d%s" % (value, t[0]) 
    20     return '%d%s' % (value, t[value % 10]) 
     19        return u"%d%s" % (value, t[0]) 
     20    return u'%d%s' % (value, t[value % 10]) 
    2121register.filter(ordinal) 
    2222 
     
    2626    For example, 3000 becomes '3,000' and 45000 becomes '45,000'. 
    2727    """ 
    28     orig = str(value) 
    29     new = re.sub("^(-?\d+)(\d{3})", '\g<1>,\g<2>', str(value)
     28    orig = force_unicode(value) 
     29    new = re.sub("^(-?\d+)(\d{3})", '\g<1>,\g<2>', orig
    3030    if orig == new: 
    3131        return new 
     
    4545    if value < 1000000000: 
    4646        new_value = value / 1000000.0 
    47         return ngettext('%(value).1f million', '%(value).1f million', new_value) % {'value': new_value} 
     47        return ungettext('%(value).1f million', '%(value).1f million', new_value) % {'value': new_value} 
    4848    if value < 1000000000000: 
    4949        new_value = value / 1000000000.0 
    50         return ngettext('%(value).1f billion', '%(value).1f billion', new_value) % {'value': new_value} 
     50        return ungettext('%(value).1f billion', '%(value).1f billion', new_value) % {'value': new_value} 
    5151    if value < 1000000000000000: 
    5252        new_value = value / 1000000000000.0 
    53         return ngettext('%(value).1f trillion', '%(value).1f trillion', new_value) % {'value': new_value} 
     53        return ungettext('%(value).1f trillion', '%(value).1f trillion', new_value) % {'value': new_value} 
    5454    return value 
    5555register.filter(intword) 
  • django/trunk/django/contrib/localflavor/au/forms.py

    r4955 r5609  
    66from django.newforms.fields import Field, RegexField, Select, EMPTY_VALUES 
    77from django.newforms.util import smart_unicode 
    8 from django.utils.translation import gettext 
     8from django.utils.translation import ugettext 
    99import re 
    1010 
     
    1616        super(AUPostCodeField, self).__init__(r'^\d{4}$', 
    1717            max_length=None, min_length=None, 
    18             error_message=gettext(u'Enter a 4 digit post code.'), 
    19             *args, **kwargs) 
     18            error_message=ugettext('Enter a 4 digit post code.'), 
     19                    *args, **kwargs) 
    2020 
    2121class AUPhoneNumberField(Field): 
    2222    """Australian phone number field.""" 
    2323    def clean(self, value): 
    24         """Validate a phone number. Strips parentheses, whitespace and 
    25         hyphens. 
     24        """ 
     25        Validate a phone number. Strips parentheses, whitespace and hyphens. 
    2626        """ 
    2727        super(AUPhoneNumberField, self).clean(value) 
     
    4040    """ 
    4141    def __init__(self, attrs=None): 
    42         from au_states import STATE_CHOICES # relative import 
     42        from au_states import STATE_CHOICES 
    4343        super(AUStateSelect, self).__init__(attrs, choices=STATE_CHOICES) 
  • django/trunk/django/contrib/localflavor/br/forms.py

    r5099 r5609  
    77from django.newforms.fields import Field, RegexField, CharField, Select, EMPTY_VALUES 
    88from django.utils.encoding import smart_unicode 
    9 from django.utils.translation import gettext 
     9from django.utils.translation import ugettext 
    1010import re 
    1111 
     
    1616        super(BRZipCodeField, self).__init__(r'^\d{5}-\d{3}$', 
    1717            max_length=None, min_length=None, 
    18             error_message=gettext('Enter a zip code in the format XXXXX-XXX.'), 
    19             *args, **kwargs) 
     18            error_message=ugettext('Enter a zip code in the format XXXXX-XXX.'), 
     19                    *args, **kwargs) 
    2020 
    2121class BRPhoneNumberField(Field): 
     
    2828        if m: 
    2929            return u'%s-%s-%s' % (m.group(1), m.group(2), m.group(3)) 
    30         raise ValidationError(gettext(u'Phone numbers must be in XX-XXXX-XXXX format.')) 
     30        raise ValidationError(ugettext('Phone numbers must be in XX-XXXX-XXXX format.')) 
    3131 
    3232class BRStateSelect(Select): 
     
    3636    """ 
    3737    def __init__(self, attrs=None): 
    38         from br_states import STATE_CHOICES # relative import 
     38        from br_states import STATE_CHOICES 
    3939        super(BRStateSelect, self).__init__(attrs, choices=STATE_CHOICES) 
    4040 
     
    7070            int(value) 
    7171        except ValueError: 
    72             raise ValidationError(gettext("This field requires only numbers.")) 
     72            raise ValidationError(ugettext("This field requires only numbers.")) 
    7373        if len(value) != 11: 
    74             raise ValidationError(gettext("This field requires at most 11 digits or 14 characters.")) 
     74            raise ValidationError(ugettext("This field requires at most 11 digits or 14 characters.")) 
    7575        orig_dv = value[-2:] 
    7676 
     
    8282        value = value[:-1] + str(new_2dv) 
    8383        if value[-2:] != orig_dv: 
    84             raise ValidationError(gettext("Invalid CPF number.")) 
     84            raise ValidationError(ugettext("Invalid CPF number.")) 
    8585 
    8686        return orig_value 
     
    104104        if len(value) != 14: 
    105105            raise ValidationError( 
    106                 gettext("This field requires at least 14 digits")) 
     106                ugettext("This field requires at least 14 digits")) 
    107107        orig_dv = value[-2:] 
    108108 
     
    114114        value = value[:-1] + str(new_2dv) 
    115115        if value[-2:] != orig_dv: 
    116             raise ValidationError(gettext("Invalid CNPJ number.")) 
     116            raise ValidationError(ugettext("Invalid CNPJ number.")) 
    117117 
    118118        return orig_value 
  • django/trunk/django/contrib/localflavor/ch/ch_states.py

    r5132 r5609  
    11# -*- coding: utf-8 -* 
    2 from django.utils.translation import gettext_lazy as _ 
     2from django.utils.translation import ugettext_lazy as _ 
    33 
    44STATE_CHOICES = ( 
  • django/trunk/django/contrib/localflavor/ch/forms.py

    r5132 r5609  
    66from django.newforms.fields import Field, RegexField, Select, EMPTY_VALUES 
    77from django.utils.encoding import smart_unicode 
    8 from django.utils.translation import gettext 
     8from django.utils.translation import ugettext 
    99import re 
    1010 
     
    1616        super(CHZipCodeField, self).__init__(r'^\d{4}$', 
    1717        max_length=None, min_length=None, 
    18         error_message=gettext('Enter a zip code in the format XXXX.'), 
     18        error_message=ugettext('Enter a zip code in the format XXXX.'), 
    1919        *args, **kwargs) 
    2020 
     
    8888    def clean(self, value): 
    8989        super(CHIdentityCardNumberField, self).clean(value) 
    90         error_msg = gettext('Enter a valid Swiss identity or passport card number in X1234567<0 or 1234567890 format.') 
     90        error_msg = ugettext('Enter a valid Swiss identity or passport card number in X1234567<0 or 1234567890 format.') 
    9191        if value in EMPTY_VALUES: 
    9292            return u'' 
  • django/trunk/django/contrib/localflavor/cl/forms.py

    r5098 r5609  
    55from django.newforms import ValidationError 
    66from django.newforms.fields import RegexField, EMPTY_VALUES 
    7 from django.utils.translation import gettext 
     7from django.utils.translation import ugettext 
     8from django.utils.encoding import smart_unicode 
    89 
    910class CLRutField(RegexField): 
     
    1920            del kwargs['strict'] 
    2021            super(CLRutField, self).__init__(r'^(\d{1,2}\.)?\d{3}\.\d{3}-[\dkK]$', 
    21                 error_message=gettext('Enter valid a Chilean RUT. The format is XX.XXX.XXX-X.'), 
    22                 *args, **kwargs) 
     22                error_message=ugettext('Enter valid a Chilean RUT. The format is XX.XXX.XXX-X.'), 
     23                        *args, **kwargs) 
    2324        else: 
    2425            # In non-strict mode, accept RUTs that validate but do not exist in 
    2526            # the real world. 
    26             super(CLRutField, self).__init__(r'^[\d\.]{1,11}-?[\dkK]$', error_message=gettext(u'Enter valid a Chilean RUT'), *args, **kwargs) 
     27            super(CLRutField, self).__init__(r'^[\d\.]{1,11}-?[\dkK]$', error_message=ugettext('Enter valid a Chilean RUT'), *args, **kwargs) 
    2728 
    2829    def clean(self, value): 
     
    5051            if multi == 8: 
    5152                multi = 2 
    52         return '0123456789K0'[11 - suma % 11] 
     53        return u'0123456789K0'[11 - suma % 11] 
    5354 
    5455    def _canonify(self, rut): 
     
    5758        tuple. 
    5859        """ 
    59         rut = str(rut).replace(' ', '').replace('.', '').replace('-', '') 
     60        rut = smart_unicode(rut).replace(' ', '').replace('.', '').replace('-', '') 
    6061        return rut[:-1], rut[-1] 
    6162 
     
    7576                new_dot = pos - 3 
    7677            code = code[:new_dot] + '.' + code[new_dot:] 
    77         return '%s-%s' % (code, verifier) 
     78        return u'%s-%s' % (code, verifier) 
    7879 
  • django/trunk/django/contrib/localflavor/de/de_states.py

    r4926 r5609  
    11# -*- coding: utf-8 -* 
    2 from django.utils.translation import gettext_lazy as _ 
     2from django.utils.translation import ugettext_lazy as _ 
    33 
    44STATE_CHOICES = ( 
  • django/trunk/django/contrib/localflavor/de/forms.py

    r4939 r5609  
    55from django.newforms import ValidationError 
    66from django.newforms.fields import Field, RegexField, Select, EMPTY_VALUES 
    7 from django.utils.translation import gettext 
     7from django.utils.translation import ugettext 
    88import re 
    99 
     
    1414        super(DEZipCodeField, self).__init__(r'^\d{5}$', 
    1515            max_length=None, min_length=None, 
    16             error_message=gettext(u'Enter a zip code in the format XXXXX.'), 
    17             *args, **kwargs) 
     16            error_message=ugettext('Enter a zip code in the format XXXXX.'), 
     17                    *args, **kwargs) 
    1818 
    1919class DEStateSelect(Select): 
     
    2222    """ 
    2323    def __init__(self, attrs=None): 
    24         from de_states import STATE_CHOICES # relative import 
     24        from de_states import STATE_CHOICES 
    2525        super(DEStateSelect, self).__init__(attrs, choices=STATE_CHOICES) 
    2626 
     
    5858    def clean(self, value): 
    5959        super(DEIdentityCardNumberField, self).clean(value) 
    60         error_msg = gettext(u'Enter a valid German identity card number in XXXXXXXXXXX-XXXXXXX-XXXXXXX-X format.') 
     60        error_msg = ugettext('Enter a valid German identity card number in XXXXXXXXXXX-XXXXXXX-XXXXXXX-X format.') 
    6161        if value in EMPTY_VALUES: 
    6262            return u'' 
     
    7272            raise ValidationError(error_msg) 
    7373 
    74         all_digits = "%s%s%s%s" % (residence, birthday, validity, checksum) 
     74        all_digits = u"%s%s%s%s" % (residence, birthday, validity, checksum) 
    7575        if not self.has_valid_checksum(residence) or not self.has_valid_checksum(birthday) or \ 
    7676            not self.has_valid_checksum(validity) or not self.has_valid_checksum(all_digits): 
  • django/trunk/django/contrib/localflavor/fi/forms.py

    r4970 r5609  
    66from django.newforms import ValidationError 
    77from django.newforms.fields import Field, RegexField, Select, EMPTY_VALUES 
    8 from django.utils.translation import gettext 
     8from django.utils.translation import ugettext 
    99 
    1010class FIZipCodeField(RegexField): 
     
    1212        super(FIZipCodeField, self).__init__(r'^\d{5}$', 
    1313            max_length=None, min_length=None, 
    14             error_message=gettext(u'Enter a zip code in the format XXXXX.'), 
    15             *args, **kwargs) 
     14            error_message=ugettext('Enter a zip code in the format XXXXX.'), 
     15                    *args, **kwargs) 
    1616 
    1717class FIMunicipalitySelect(Select): 
     
    2020    """ 
    2121    def __init__(self, attrs=None): 
    22         from fi_municipalities import MUNICIPALITY_CHOICES # relative import 
     22        from fi_municipalities import MUNICIPALITY_CHOICES 
    2323        super(FIMunicipalitySelect, self).__init__(attrs, choices=MUNICIPALITY_CHOICES) 
    2424 
     
    3838            (?P<checksum>[%s])$""" % checkmarks, value, re.VERBOSE | re.IGNORECASE) 
    3939        if not result: 
    40             raise ValidationError(gettext(u'Enter a valid Finnish social security number.')) 
     40            raise ValidationError(ugettext('Enter a valid Finnish social security number.')) 
    4141        gd = result.groupdict() 
    4242        checksum = int(gd['date'] + gd['serial']) 
    4343        if checkmarks[checksum % len(checkmarks)] == gd['checksum'].upper(): 
    4444            return u'%s' % value.upper() 
    45         raise ValidationError(gettext(u'Enter a valid Finnish social security number.')) 
     45        raise ValidationError(ugettext('Enter a valid Finnish social security number.')) 
  • django/trunk/django/contrib/localflavor/fr/forms.py

    r4918 r5609  
    66from django.newforms.fields import Field, RegexField, Select, EMPTY_VALUES 
    77from django.utils.encoding import smart_unicode 
    8 from django.utils.translation import gettext 
     8from django.utils.translation import ugettext 
    99import re 
    1010 
     
    1515        super(FRZipCodeField, self).__init__(r'^\d{5}$', 
    1616            max_length=None, min_length=None, 
    17             error_message=gettext(u'Enter a zip code in the format XXXXX.'), 
    18             *args, **kwargs) 
     17            error_message=ugettext('Enter a zip code in the format XXXXX.'), 
     18                    *args, **kwargs) 
    1919 
    2020class FRPhoneNumberField(Field): 
     
    4040    """ 
    4141    def __init__(self, attrs=None): 
    42         from fr_department import DEPARTMENT_ASCII_CHOICES # relative import 
     42        from fr_department import DEPARTMENT_ASCII_CHOICES 
    4343        super(FRDepartmentSelect, self).__init__(attrs, choices=DEPARTMENT_ASCII_CHOICES) 
    4444 
  • django/trunk/django/contrib/localflavor/is_/forms.py

    r5210 r5609  
    66from django.newforms.fields import RegexField, EMPTY_VALUES 
    77from django.newforms.widgets import Select 
    8 from django.utils.translation import gettext 
     8from django.utils.translation import ugettext 
     9from django.utils.encoding import smart_unicode 
    910 
    1011class ISIdNumberField(RegexField): 
     
    1415    """ 
    1516    def __init__(self, *args, **kwargs): 
    16         error_msg = gettext(u'Enter a valid Icelandic identification number. The format is XXXXXX-XXXX.') 
     17        error_msg = ugettext('Enter a valid Icelandic identification number. The format is XXXXXX-XXXX.') 
    1718        kwargs['min_length'],kwargs['max_length'] = 10,11 
    1819        super(ISIdNumberField, self).__init__(r'^\d{6}(-| )?\d{4}$', error_message=error_msg, *args, **kwargs) 
     
    2829            return self._format(value) 
    2930        else: 
    30             raise ValidationError(gettext(u'The Icelandic identification number is not valid.')) 
     31            raise ValidationError(ugettext(u'The Icelandic identification number is not valid.')) 
    3132 
    3233    def _canonify(self, value): 
     
    4950        display format. 
    5051        """ 
    51         return value[:6]+'-'+value[6:] 
     52        return smart_unicode(value[:6]+'-'+value[6:]) 
    5253 
    5354class ISPhoneNumberField(RegexField): 
  • django/trunk/django/contrib/localflavor/it/forms.py

    r5018 r5609  
    55from django.newforms import ValidationError 
    66from django.newforms.fields import Field, RegexField, Select, EMPTY_VALUES 
    7 from django.utils.translation import gettext 
     7from django.utils.translation import ugettext 
    88from django.utils.encoding import smart_unicode 
    99from django.contrib.localflavor.it.util import ssn_check_digit, vat_number_check_digit 
     
    1414        super(ITZipCodeField, self).__init__(r'^\d{5}$', 
    1515        max_length=None, min_length=None, 
    16         error_message=gettext(u'Enter a valid zip code.'), 
    17         *args, **kwargs) 
     16        error_message=ugettext('Enter a valid zip code.'), 
     17                *args, **kwargs) 
    1818 
    1919class ITRegionSelect(Select): 
     
    2222    """ 
    2323    def __init__(self, attrs=None): 
    24         from it_region import REGION_CHOICES # relative import 
     24        from it_region import REGION_CHOICES 
    2525        super(ITRegionSelect, self).__init__(attrs, choices=REGION_CHOICES) 
    2626 
     
    3030    """ 
    3131    def __init__(self, attrs=None): 
    32         from it_province import PROVINCE_CHOICES # relative import 
     32        from it_province import PROVINCE_CHOICES 
    3333        super(ITProvinceSelect, self).__init__(attrs, choices=PROVINCE_CHOICES) 
    3434 
     
    3939    'Informazioni sulla codificazione delle persone fisiche'. 
    4040    """ 
    41     err_msg = gettext(u'Enter a valid Social Security number.') 
     41    err_msg = ugettext(u'Enter a valid Social Security number.') 
    4242    def __init__(self, *args, **kwargs): 
    4343        super(ITSocialSecurityNumberField, self).__init__(r'^\w{3}\s*\w{3}\s*\w{5}\s*\w{5}$', 
     
    6666        if value == u'': 
    6767            return value 
    68         err_msg = gettext(u'Enter a valid VAT number.') 
     68        err_msg = ugettext(u'Enter a valid VAT number.') 
    6969        try: 
    7070            vat_number = int(value) 
  • django/trunk/django/contrib/localflavor/it/it_province.py

    r4862 r5609  
    3434    ('CN', 'Cuneo'), 
    3535    ('EN', 'Enna'), 
    36 #    ('FM', 'Fermo'), # active starting from 2009     
     36#    ('FM', 'Fermo'), # active starting from 2009 
    3737    ('FE', 'Ferrara'), 
    3838    ('FI', 'Firenze'), 
  • django/trunk/django/contrib/localflavor/it/util.py

    r5018 r5609  
     1from django.utils.encoding import smart_str, smart_unicode 
     2 
    13def ssn_check_digit(value): 
    24    "Calculate Italian social security number check digit." 
    35    ssn_even_chars = { 
    4         '0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9, 
    5         'A': 0, 'B': 1, 'C': 2, 'D': 3, 'E': 4, 'F': 5, 'G': 6, 'H': 7, 'I': 8, 'J': 9, 
    6         'K': 10, 'L': 11, 'M': 12, 'N': 13, 'O': 14, 'P': 15, 'Q': 16, 'R': 17, 'S': 18, 
    7         'T': 19, 'U': 20, 'V': 21, 'W': 22, 'X': 23, 'Y': 24, 'Z': 25 
     6        '0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, 
     7        '9': 9, 'A': 0, 'B': 1, 'C': 2, 'D': 3, 'E': 4, 'F': 5, 'G': 6, 'H': 7, 
     8        'I': 8, 'J': 9, 'K': 10, 'L': 11, 'M': 12, 'N': 13, 'O': 14, 'P': 15, 
     9        'Q': 16, 'R': 17, 'S': 18, 'T': 19, 'U': 20, 'V': 21, 'W': 22, 'X': 23, 
     10        'Y': 24, 'Z': 25 
    811    } 
    912    ssn_odd_chars = { 
    10         '0': 1, '1': 0, '2': 5, '3': 7, '4': 9, '5': 13, '6': 15, '7': 17, '8': 19, '9': 21, 
    11         'A': 1, 'B': 0, 'C': 5, 'D': 7, 'E': 9, 'F': 13, 'G': 15, 'H': 17, 'I': 19, 'J': 21, 
    12         'K': 2, 'L': 4, 'M': 18, 'N': 20, 'O': 11, 'P': 3, 'Q': 6, 'R': 8, 'S': 12, 
    13         'T': 14, 'U': 16, 'V': 10, 'W': 22, 'X': 25, 'Y': 24, 'Z': 23 
     13        '0': 1, '1': 0, '2': 5, '3': 7, '4': 9, '5': 13, '6': 15, '7': 17, '8': 
     14        19, '9': 21, 'A': 1, 'B': 0, 'C': 5, 'D': 7, 'E': 9, 'F': 13, 'G': 15, 
     15        'H': 17, 'I': 19, 'J': 21, 'K': 2, 'L': 4, 'M': 18, 'N': 20, 'O': 11, 
     16        'P': 3, 'Q': 6, 'R': 8, 'S': 12, 'T': 14, 'U': 16, 'V': 10, 'W': 22, 
     17        'X': 25, 'Y': 24, 'Z': 23 
    1418    } 
    1519    # Chars from 'A' to 'Z' 
     
    1822    ssn = value.upper() 
    1923    total = 0 
    20     for i in range(0,15): 
     24    for i in range(0, 15): 
    2125        try: 
    2226            if i % 2 == 0: 
     
    3135def vat_number_check_digit(vat_number): 
    3236    "Calculate Italian VAT number check digit." 
    33     normalized_vat_number = str(vat_number).zfill(10) 
     37    normalized_vat_number = smart_str(vat_number).zfill(10) 
    3438    total = 0 
    3539    for i in range(0, 10, 2): 
     
    3842        quotient , remainder = divmod(int(normalized_vat_number[i]) * 2, 10) 
    3943        total += quotient + remainder 
    40     return str((10 - total % 10) % 10) 
     44    return smart_unicode((10 - total % 10) % 10) 
  • django/trunk/django/contrib/localflavor/jp/forms.py

    r4822 r5609  
    55from django.core import validators 
    66from django.newforms import ValidationError 
    7 from django.utils.translation import gettext 
     7from django.utils.translation import ugettext 
    88from django.newforms.fields import RegexField, Select 
    99 
     
    1919        super(JPPostalCodeField, self).__init__(r'^\d{3}-\d{4}$|^\d{7}$', 
    2020            max_length=None, min_length=None, 
    21             error_message=gettext(u'Enter a postal code in the format XXXXXXX or XXX-XXXX.'), 
    22             *args, **kwargs) 
     21            error_message=ugettext('Enter a postal code in the format XXXXXXX or XXX-XXXX.'), 
     22                    *args, **kwargs) 
    2323 
    2424    def clean(self, value): 
  • django/trunk/django/contrib/localflavor/jp/jp_prefectures.py

    r4822 r5609  
    1 from django.utils.translation import gettext_lazy as gettext_lazy 
     1from django.utils.translation import ugettext_lazy 
    22 
    33JP_PREFECTURES = ( 
    4     ('hokkaido', gettext_lazy('Hokkaido'),), 
    5     ('aomori', gettext_lazy('Aomori'),), 
    6     ('iwate', gettext_lazy('Iwate'),), 
    7     ('miyagi', gettext_lazy('Miyagi'),), 
    8     ('akita', gettext_lazy('Akita'),), 
    9     ('yamagata', gettext_lazy('Yamagata'),), 
    10     ('fukushima', gettext_lazy('Fukushima'),), 
    11     ('ibaraki', gettext_lazy('Ibaraki'),), 
    12     ('tochigi', gettext_lazy('Tochigi'),), 
    13     ('gunma', gettext_lazy('Gunma'),), 
    14     ('saitama', gettext_lazy('Saitama'),), 
    15     ('chiba', gettext_lazy('Chiba'),), 
    16     ('tokyo', gettext_lazy('Tokyo'),), 
    17     ('kanagawa', gettext_lazy('Kanagawa'),), 
    18     ('yamanashi', gettext_lazy('Yamanashi'),), 
    19     ('nagano', gettext_lazy('Nagano'),), 
    20     ('niigata', gettext_lazy('Niigata'),), 
    21     ('toyama', gettext_lazy('Toyama'),), 
    22     ('ishikawa', gettext_lazy('Ishikawa'),), 
    23     ('fukui', gettext_lazy('Fukui'),), 
    24     ('gifu', gettext_lazy('Gifu'),), 
    25     ('shizuoka', gettext_lazy('Shizuoka'),), 
    26     ('aichi', gettext_lazy('Aichi'),), 
    27     ('mie', gettext_lazy('Mie'),), 
    28     ('shiga', gettext_lazy('Shiga'),), 
    29     ('kyoto', gettext_lazy('Kyoto'),), 
    30     ('osaka', gettext_lazy('Osaka'),), 
    31     ('hyogo', gettext_lazy('Hyogo'),), 
    32     ('nara', gettext_lazy('Nara'),), 
    33     ('wakayama', gettext_lazy('Wakayama'),), 
    34     ('tottori', gettext_lazy('Tottori'),), 
    35     ('shimane', gettext_lazy('Shimane'),), 
    36     ('okayama', gettext_lazy('Okayama'),), 
    37     ('hiroshima', gettext_lazy('Hiroshima'),), 
    38     ('yamaguchi', gettext_lazy('Yamaguchi'),), 
    39     ('tokushima', gettext_lazy('Tokushima'),), 
    40     ('kagawa', gettext_lazy('Kagawa'),), 
    41     ('ehime', gettext_lazy('Ehime'),), 
    42     ('kochi', gettext_lazy('Kochi'),), 
    43     ('fukuoka', gettext_lazy('Fukuoka'),), 
    44     ('saga', gettext_lazy('Saga'),), 
    45     ('nagasaki', gettext_lazy('Nagasaki'),), 
    46     ('kumamoto', gettext_lazy('Kumamoto'),), 
    47     ('oita', gettext_lazy('Oita'),), 
    48     ('miyazaki', gettext_lazy('Miyazaki'),), 
    49     ('kagoshima', gettext_lazy('Kagoshima'),), 
    50     ('okinawa', gettext_lazy('Okinawa'),), 
     4    ('hokkaido', ugettext_lazy('Hokkaido'),), 
     5    ('aomori', ugettext_lazy('Aomori'),), 
     6    ('iwate', ugettext_lazy('Iwate'),), 
     7    ('miyagi', ugettext_lazy('Miyagi'),), 
     8    ('akita', ugettext_lazy('Akita'),), 
     9    ('yamagata', ugettext_lazy('Yamagata'),), 
     10    ('fukushima', ugettext_lazy('Fukushima'),), 
     11    ('ibaraki', ugettext_lazy('Ibaraki'),), 
     12    ('tochigi', ugettext_lazy('Tochigi'),), 
     13    ('gunma', ugettext_lazy('Gunma'),), 
     14    ('saitama', ugettext_lazy('Saitama'),), 
     15    ('chiba', ugettext_lazy('Chiba'),), 
     16    ('tokyo', ugettext_lazy('Tokyo'),), 
     17    ('kanagawa', ugettext_lazy('Kanagawa'),), 
     18    ('yamanashi', ugettext_lazy('Yamanashi'),), 
     19    ('nagano', ugettext_lazy('Nagano'),), 
     20    ('niigata', ugettext_lazy('Niigata'),), 
     21    ('toyama', ugettext_lazy('Toyama'),), 
     22    ('ishikawa', ugettext_lazy('Ishikawa'),), 
     23    ('fukui', ugettext_lazy('Fukui'),), 
     24    ('gifu', ugettext_lazy('Gifu'),), 
     25    ('shizuoka', ugettext_lazy('Shizuoka'),), 
     26    ('aichi', ugettext_lazy('Aichi'),), 
     27    ('mie', ugettext_lazy('Mie'),), 
     28    ('shiga', ugettext_lazy('Shiga'),), 
     29    ('kyoto', ugettext_lazy('Kyoto'),), 
     30    ('osaka', ugettext_lazy('Osaka'),), 
     31    ('hyogo', ugettext_lazy('Hyogo'),), 
     32    ('nara', ugettext_lazy('Nara'),), 
     33    ('wakayama', ugettext_lazy('Wakayama'),), 
     34    ('tottori', ugettext_lazy('Tottori'),), 
     35    ('shimane', ugettext_lazy('Shimane'),), 
     36    ('okayama', ugettext_lazy('Okayama'),), 
     37    ('hiroshima', ugettext_lazy('Hiroshima'),), 
     38    ('yamaguchi', ugettext_lazy('Yamaguchi'),), 
     39    ('tokushima', ugettext_lazy('Tokushima'),), 
     40    ('kagawa', ugettext_lazy('Kagawa'),), 
     41    ('ehime', ugettext_lazy('Ehime'),), 
     42    ('kochi', ugettext_lazy('Kochi'),), 
     43    ('fukuoka', ugettext_lazy('Fukuoka'),), 
     44    ('saga', ugettext_lazy('Saga'),), 
     45    ('nagasaki', ugettext_lazy('Nagasaki'),), 
     46    ('kumamoto', ugettext_lazy('Kumamoto'),), 
     47    ('oita', ugettext_lazy('Oita'),), 
     48    ('miyazaki', ugettext_lazy('Miyazaki'),), 
     49    ('kagoshima', ugettext_lazy('Kagoshima'),), 
     50    ('okinawa', ugettext_lazy('Okinawa'),), 
    5151) 
  • django/trunk/django/contrib/localflavor/no/forms.py

    r4888 r5609  
    77from django.newforms import ValidationError 
    88from django.newforms.fields import Field, RegexField, Select, EMPTY_VALUES 
    9 from django.utils.translation import gettext 
     9from django.utils.translation import ugettext 
    1010 
    1111class NOZipCodeField(RegexField): 
     
    1313        super(NOZipCodeField, self).__init__(r'^\d{4}$', 
    1414            max_length=None, min_length=None, 
    15             error_message=gettext(u'Enter a zip code in the format XXXX.'), 
    16             *args, **kwargs) 
     15            error_message=ugettext('Enter a zip code in the format XXXX.'), 
     16                    *args, **kwargs) 
    1717 
    1818class NOMunicipalitySelect(Select): 
     
    3434            return u'' 
    3535 
    36         msg = gettext(u'Enter a valid Norwegian social security number.') 
     36        msg = ugettext(u'Enter a valid Norwegian social security number.') 
    3737        if not re.match(r'^\d{11}$', value): 
    3838            raise ValidationError(msg) 
     
    6161        else: 
    6262            self.gender = 'M' 
    63          
     63 
    6464        digits = map(int, list(value)) 
    6565        weight_1 = [3, 7, 6, 1, 8, 9, 4, 5, 2, 1, 0] 
     
    7575 
    7676        return value 
    77      
     77 
  • django/trunk/django/contrib/localflavor/no/no_municipalities.py

    r4875 r5609  
    1 # -*- coding: iso-8859-1 -*- 
     1# -*- coding: utf-8 -*- 
    22""" 
    33An alphabetical list of Norwegian municipalities (fylker) fro use as `choices` 
     
    1616    ('hordaland', u'Hordaland'), 
    1717    ('janmayen', u'Jan Mayen'), 
    18     ('moreogromsdal', u'Mg Romsdal'), 
    19     ('nordtrondelag', u'Nord-Trag'), 
     18    ('moreogromsdal', u'Møre og Romsdal'), 
     19    ('nordtrondelag', u'Nord-Trøndelag'), 
    2020    ('nordland', u'Nordland'), 
    2121    ('oppland', u'Oppland'), 
     
    2424    ('sognogfjordane', u'Sogn og Fjordane'), 
    2525    ('svalbard', u'Svalbard'), 
    26     ('sortrondelag', u'S��ag'), 
     26    ('sortrondelag', u'Sør-Trøndelag'), 
    2727    ('telemark', u'Telemark'), 
    2828    ('troms', u'Troms'), 
    2929    ('vestagder', u'Vest-Agder'), 
    3030    ('vestfold', u'Vestfold'), 
    31     ('ostfold', u'tfold') 
     31    ('ostfold', u'Østfold') 
    3232) 
  • django/trunk/django/contrib/localflavor/uk/forms.py

    r4527 r5609  
    44 
    55from django.newforms.fields import RegexField 
    6 from django.utils.translation import gettext 
     6from django.utils.translation import ugettext 
    77 
    88class UKPostcodeField(RegexField): 
     
    1616        super(UKPostcodeField, self).__init__(r'^(GIR 0AA|[A-PR-UWYZ]([0-9]{1,2}|([A-HIK-Y][0-9](|[0-9]|[ABEHMNPRVWXY]))|[0-9][A-HJKSTUW]) [0-9][ABD-HJLNP-UW-Z]{2})$', 
    1717            max_length=None, min_length=None, 
    18             error_message=gettext(u'Enter a postcode. A space is required between the two postcode parts.'), 
     18            error_message=ugettext(u'Enter a postcode. A space is required between the two postcode parts.'), 
    1919            *args, **kwargs) 
  • django/trunk/django/contrib/localflavor/us/forms.py

    r4918 r5609  
    66from django.newforms.fields import Field, RegexField, Select, EMPTY_VALUES 
    77from django.utils.encoding import smart_unicode 
    8 from django.utils.translation import gettext 
     8from django.utils.translation import ugettext 
    99import re 
    1010 
     
    1616        super(USZipCodeField, self).__init__(r'^\d{5}(?:-\d{4})?$', 
    1717            max_length=None, min_length=None, 
    18             error_message=gettext(u'Enter a zip code in the format XXXXX or XXXXX-XXXX.'), 
    19             *args, **kwargs) 
     18            error_message=ugettext('Enter a zip code in the format XXXXX or XXXXX-XXXX.'), 
     19                    *args, **kwargs) 
    2020 
    2121class USPhoneNumberField(Field): 
     
    3939        * No group consists entirely of zeroes. 
    4040        * The leading group is not "666" (block "666" will never be allocated). 
    41         * The number is not in the promotional block 987-65-4320 through 987-65-4329, 
    42           which are permanently invalid. 
     41        * The number is not in the promotional block 987-65-4320 through 
     42          987-65-4329, which are permanently invalid. 
    4343        * The number is not one known to be invalid due to otherwise widespread 
    44           promotional use or distribution (e.g., the Woolworth's number or the 1962 
    45           promotional number). 
     44          promotional use or distribution (e.g., the Woolworth's number or the 
     45          1962 promotional number). 
    4646    """ 
    4747    def clean(self, value): 
     
    4949        if value in EMPTY_VALUES: 
    5050            return u'' 
    51         msg = gettext(u'Enter a valid U.S. Social Security number in XXX-XX-XXXX format.') 
     51        msg = ugettext('Enter a valid U.S. Social Security number in XXX-XX-XXXX format.') 
    5252        match = re.match(ssn_re, value) 
    5353        if not match: 
     
    7676    """ 
    7777    def clean(self, value): 
    78         from us_states import STATES_NORMALIZED # relative import 
     78        from us_states import STATES_NORMALIZED 
    7979        super(USStateField, self).clean(value) 
    8080        if value in EMPTY_VALUES: 
     
    9696    """ 
    9797    def __init__(self, attrs=None): 
    98         from us_states import STATE_CHOICES # relative import 
     98        from us_states import STATE_CHOICES 
    9999        super(USStateSelect, self).__init__(attrs, choices=STATE_CHOICES) 
  • django/trunk/django/contrib/markup/templatetags/markup.py

    r4265 r5609  
    1717from django import template 
    1818from django.conf import settings 
     19from django.utils.encoding import smart_str, force_unicode 
    1920 
    2021register = template.Library() 
     
    2627        if settings.DEBUG: 
    2728            raise template.TemplateSyntaxError, "Error in {% textile %} filter: The Python textile library isn't installed." 
    28         return value 
     29        return force_unicode(value) 
    2930    else: 
    30         return textile.textile(value, encoding=settings.DEFAULT_CHARSET, output=settings.DEFAULT_CHARSET
     31        return force_unicode(textile.textile(smart_str(value), encoding='utf-8', output='utf-8')
    3132 
    3233def markdown(value): 
     
    3637        if settings.DEBUG: 
    3738            raise template.TemplateSyntaxError, "Error in {% markdown %} filter: The Python markdown library isn't installed." 
    38         return value 
     39        return force_unicode(value) 
    3940    else: 
    40         return markdown.markdown(value
     41        return force_unicode(markdown.markdown(smart_str(value))
    4142 
    4243def restructuredtext(value): 
     
    4647        if settings.DEBUG: 
    4748            raise template.TemplateSyntaxError, "Error in {% restructuredtext %} filter: The Python docutils library isn't installed." 
    48         return value 
     49        return force_unicode(value) 
    4950    else: 
    5051        docutils_settings = getattr(settings, "RESTRUCTUREDTEXT_FILTER_SETTINGS", {}) 
    51         parts = publish_parts(source=value, writer_name="html4css1", settings_overrides=docutils_settings) 
    52         return parts["fragment"] 
     52        parts = publish_parts(source=smart_str(value), writer_name="html4css1", settings_overrides=docutils_settings) 
     53        return force_unicode(parts["fragment"]) 
    5354 
    5455register.filter(textile) 
  • django/trunk/django/contrib/redirects/models.py

    r4265 r5609  
    11from django.db import models 
    22from django.contrib.sites.models import Site 
    3 from django.utils.translation import gettext_lazy as _ 
     3from django.utils.translation import ugettext_lazy as _ 
    44 
    55class Redirect(models.Model): 
     
    2121        search_fields = ('old_path', 'new_path') 
    2222 
    23     def __str__(self): 
    24         return "%s ---> %s" % (self.old_path, self.new_path) 
     23    def __unicode__(self): 
     24        return u"%s ---> %s" % (self.old_path, self.new_path) 
  • django/trunk/django/contrib/sessions/models.py

    r5470 r5609  
    22import cPickle as pickle 
    33from django.db import models 
    4 from django.utils.translation import gettext_lazy as _ 
     4from django.utils.translation import ugettext_lazy as _ 
    55from django.conf import settings 
    66 
  • django/trunk/django/contrib/sitemaps/views.py

    r5091 r5609  
    33from django.contrib.sites.models import Site 
    44from django.core import urlresolvers 
     5from django.utils.encoding import smart_str 
    56 
    67def index(request, sitemaps): 
     
    2728        else: 
    2829            urls.extend(site.get_urls()) 
    29     xml = loader.render_to_string('sitemap.xml', {'urlset': urls}
     30    xml = smart_str(loader.render_to_string('sitemap.xml', {'urlset': urls})
    3031    return HttpResponse(xml, mimetype='application/xml') 
  • django/trunk/django/contrib/sites/models.py

    r4265 r5609  
    11from django.db import models 
    2 from django.utils.translation import gettext_lazy as _ 
     2from django.utils.translation import ugettext_lazy as _ 
    33 
    44class SiteManager(models.Manager): 
     
    2020        search_fields = ('domain', 'name') 
    2121 
    22     def __str__(self): 
     22    def __unicode__(self): 
    2323        return self.domain 
  • django/trunk/django/contrib/syndication/feeds.py

    r5045 r5609  
    33from django.contrib.sites.models import Site 
    44from django.utils import feedgenerator 
     5from django.utils.encoding import smart_unicode 
    56from django.conf import settings 
    67 
    78def add_domain(domain, url): 
    89    if not url.startswith('http://'): 
     10        # 'url' must already be ASCII and URL-quoted, so no need for encoding 
     11        # conversions here. 
    912        url = u'http://%s%s' % (domain, url) 
    1013    return url 
     
    98101            if enc_url: 
    99102                enc = feedgenerator.Enclosure( 
    100                     url = enc_url.decode('utf-8'), 
    101                     length = str(self.__get_dynamic_attr('item_enclosure_length', item)).decode('utf-8'), 
    102                     mime_type = self.__get_dynamic_attr('item_enclosure_mime_type', item).decode('utf-8'), 
     103                    url = smart_unicode(enc_url), 
     104                    length = smart_unicode(self.__get_dynamic_attr('item_enclosure_length', item)), 
     105                    mime_type = smart_unicode(self.__get_dynamic_attr('item_enclosure_mime_type', item)) 
    103106                ) 
    104107            author_name = self.__get_dynamic_attr('item_author_name', item) 
     
    109112                author_email = author_link = None 
    110113            feed.add_item( 
    111                 title = title_tmp.render(Context({'obj': item, 'site': current_site})).decode('utf-8')
     114                title = title_tmp.render(Context({'obj': item, 'site': current_site}))
    112115                link = link, 
    113                 description = description_tmp.render(Context({'obj': item, 'site': current_site})).decode('utf-8')
     116                description = description_tmp.render(Context({'obj': item, 'site': current_site}))
    114117                unique_id = link, 
    115118                enclosure = enc, 
  • django/trunk/django/contrib/webdesign/lorem_ipsum.py

    r5190 r5609  
    66 
    77COMMON_P = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.' 
    8 WORDS = ('exercitationem', 'perferendis', 'perspiciatis', 'laborum', 'eveniet', 'sunt', 'iure', 'nam', 'nobis', 'eum', 'cum', 'officiis', 'excepturi', 'odio', 'consectetur', 'quasi', 'aut', 'quisquam', 'vel', 'eligendi', 'itaque', 'non', 'odit', 'tempore', 'quaerat', 'dignissimos', 'facilis', 'neque', 'nihil', 'expedita', 'vitae', 'vero', 'ipsum', 'nisi', 'animi', 'cumque', 'pariatur', 'velit', 'modi', 'natus', 'iusto', 'eaque', 'sequi', 'illo', 'sed', 'ex', 'et', 'voluptatibus', 'tempora', 'veritatis', 'ratione', 'assumenda', 'incidunt', 'nostrum', 'placeat', 'aliquid', 'fuga', 'provident', 'praesentium', 'rem', 'necessitatibus', 'suscipit', 'adipisci', 'quidem', 'possimus', 'voluptas', 'debitis', 'sint', 'accusantium', 'unde', 'sapiente', 'voluptate', 'qui', 'aspernatur', 'laudantium', 'soluta', 'amet', 'quo', 'aliquam', 'saepe', 'culpa', 'libero', 'ipsa', 'dicta', 'reiciendis', 'nesciunt', 'doloribus', 'autem', 'impedit', 'minima', 'maiores', 'repudiandae', 'ipsam', 'obcaecati', 'ullam', 'enim', 'totam', 'delectus', 'ducimus', 'quis', 'voluptates', 'dolores', 'molestiae', 'harum', 'dolorem', 'quia', 'voluptatem', 'molestias', 'magni', 'distinctio', 'omnis', 'illum', 'dolorum', 'voluptatum', 'ea', 'quas', 'quam', 'corporis', 'quae', 'blanditiis', 'atque', 'deserunt', 'laboriosam', 'earum', 'consequuntur', 'hic', 'cupiditate', 'quibusdam', 'accusamus', 'ut', 'rerum', 'error', 'minus', 'eius', 'ab', 'ad', 'nemo', 'fugit', 'officia', 'at', 'in', 'id', 'quos', 'reprehenderit', 'numquam', 'iste', 'fugiat', 'sit', 'inventore', 'beatae', 'repellendus', 'magnam', 'recusandae', 'quod', 'explicabo', 'doloremque', 'aperiam', 'consequatur', 'asperiores', 'commodi', 'optio', 'dolor', 'labore', 'temporibus', 'repellat', 'veniam', 'architecto', 'est', 'esse', 'mollitia', 'nulla', 'a', 'similique', 'eos', 'alias', 'dolore', 'tenetur', 'deleniti', 'porro', 'facere', 'maxime', 'corrupti') 
    9 COMMON_WORDS = ('lorem', 'ipsum', 'dolor', 'sit', 'amet', 'consectetur', 'adipisicing', 'elit', 'sed', 'do', 'eiusmod', 'tempor', 'incididunt', 'ut', 'labore', 'et', 'dolore', 'magna', 'aliqua') 
     8 
     9WORDS = ('exercitationem', 'perferendis', 'perspiciatis', 'laborum', 'eveniet', 
     10        'sunt', 'iure', 'nam', 'nobis', 'eum', 'cum', 'officiis', 'excepturi', 
     11        'odio', 'consectetur', 'quasi', 'aut', 'quisquam', 'vel', 'eligendi', 
     12        'itaque', 'non', 'odit', 'tempore', 'quaerat', 'dignissimos', 
     13        'facilis', 'neque', 'nihil', 'expedita', 'vitae', 'vero', 'ipsum', 
     14        'nisi', 'animi', 'cumque', 'pariatur', 'velit', 'modi', 'natus', 
     15        'iusto', 'eaque', 'sequi', 'illo', 'sed', 'ex', 'et', 'voluptatibus', 
     16        'tempora', 'veritatis', 'ratione', 'assumenda', 'incidunt', 'nostrum', 
     17        'placeat', 'aliquid', 'fuga', 'provident', 'praesentium', 'rem', 
     18        'necessitatibus', 'suscipit', 'adipisci', 'quidem', 'possimus', 
     19        'voluptas', 'debitis', 'sint', 'accusantium', 'unde', 'sapiente', 
     20        'voluptate', 'qui', 'aspernatur', 'laudantium', 'soluta', 'amet', 
     21        'quo', 'aliquam', 'saepe', 'culpa', 'libero', 'ipsa', 'dicta', 
     22        'reiciendis', 'nesciunt', 'doloribus', 'autem', 'impedit', 'minima', 
     23        'maiores', 'repudiandae', 'ipsam', 'obcaecati', 'ullam', 'enim', 
     24        'totam', 'delectus', 'ducimus', 'quis', 'voluptates', 'dolores', 
     25        'molestiae', 'harum', 'dolorem', 'quia', 'voluptatem', 'molestias', 
     26        'magni', 'distinctio', 'omnis', 'illum', 'dolorum', 'voluptatum', 'ea', 
     27        'quas', 'quam', 'corporis', 'quae', 'blanditiis', 'atque', 'deserunt', 
     28        'laboriosam', 'earum', 'consequuntur', 'hic', 'cupiditate', 
     29        'quibusdam', 'accusamus', 'ut', 'rerum', 'error', 'minus', 'eius', 
     30        'ab', 'ad', 'nemo', 'fugit', 'officia', 'at', 'in', 'id', 'quos', 
     31        'reprehenderit', 'numquam', 'iste', 'fugiat', 'sit', 'inventore', 
     32        'beatae', 'repellendus', 'magnam', 'recusandae', 'quod', 'explicabo', 
     33        'doloremque', 'aperiam', 'consequatur', 'asperiores', 'commodi', 
     34        'optio', 'dolor', 'labore', 'temporibus', 'repellat', 'veniam', 
     35        'architecto', 'est', 'esse', 'mollitia', 'nulla', 'a', 'similique', 
     36        'eos', 'alias', 'dolore', 'tenetur', 'deleniti', 'porro', 'facere', 
     37        'maxime', 'corrupti') 
     38 
     39COMMON_WORDS = ('lorem', 'ipsum', 'dolor', 'sit', 'amet', 'consectetur', 
     40        'adipisicing', 'elit', 'sed', 'do', 'eiusmod', 'tempor', 'incididunt', 
     41        'ut', 'labore', 'et', 'dolore', 'magna', 'aliqua') 
    1042 
    1143def sentence(): 
     
    1850    # Determine the number of comma-separated sections and number of words in 
    1951    # each section for this sentence. 
    20     sections = [' '.join(random.sample(WORDS, random.randint(3, 12))) for i in range(random.randint(1, 5))] 
    21     s = ', '.join(sections) 
     52    sections = [u' '.join(random.sample(WORDS, random.randint(3, 12))) for i in range(random.randint(1, 5))] 
     53    s = u', '.join(sections) 
    2254    # Convert to sentence case and add end punctuation. 
    23     return '%s%s%s' % (s[0].upper(), s[1:], random.choice('?.')) 
     55    return u'%s%s%s' % (s[0].upper(), s[1:], random.choice('?.')) 
    2456 
    2557def paragraph(): 
     
    2961    The paragraph consists of between 1 and 4 sentences, inclusive. 
    3062    """ 
    31     return ' '.join([sentence() for i in range(random.randint(1, 4))]) 
     63    return u' '.join([sentence() for i in range(random.randint(1, 4))]) 
    3264 
    3365def paragraphs(count, common=True): 
     
    6799    else: 
    68100        word_list = word_list[:count] 
    69     return ' '.join(word_list) 
     101    return u' '.join(word_list) 
  • django/trunk/django/contrib/webdesign/templatetags/webdesign.py

    r5189 r5609  
    1919        if self.method == 'p': 
    2020            paras = ['<p>%s</p>' % p for p in paras] 
    21         return '\n\n'.join(paras) 
     21        return u'\n\n'.join(paras) 
    2222 
    2323#@register.tag 
  • django/trunk/django/contrib/webdesign/tests.py

    r5296 r5609  
    33r""" 
    44>>> words(7) 
    5 'lorem ipsum dolor sit amet consectetur adipisicing' 
     5u'lorem ipsum dolor sit amet consectetur adipisicing' 
    66 
    77>>> paragraphs(1) 
  • django/trunk/django/core/handlers/modpython.py

    r5091 r5609  
    5050            self._post, self._files = http.parse_file_upload(self._req.headers_in, self.raw_post_data) 
    5151        else: 
    52             self._post, self._files = http.QueryDict(self.raw_post_data), datastructures.MultiValueDict() 
     52            self._post, self._files = http.QueryDict(self.raw_post_data, encoding=self._encoding), datastructures.MultiValueDict() 
    5353 
    5454    def _get_request(self): 
     
    5959    def _get_get(self): 
    6060        if not hasattr(self, '_get'): 
    61             self._get = http.QueryDict(self._req.args
     61            self._get = http.QueryDict(self._req.args, encoding=self._encoding
    6262        return self._get 
    6363 
     
    161161        for key, value in response.headers.items(): 
    162162            if key != 'Content-Type': 
    163                 req.headers_out[key] = value 
     163                req.headers_out[str(key)] = str(value) 
    164164        for c in response.cookies.values(): 
    165165            req.headers_out.add('Set-Cookie', c.output(header='')) 
  • django/trunk/django/core/handlers/wsgi.py

    r5091 r5609  
    114114                self._post, self._files = http.parse_file_upload(header_dict, self.raw_post_data) 
    115115            else: 
    116                 self._post, self._files = http.QueryDict(self.raw_post_data), datastructures.MultiValueDict() 
     116                self._post, self._files = http.QueryDict(self.raw_post_data, encoding=self._encoding), datastructures.MultiValueDict() 
    117117        else: 
    118             self._post, self._files = http.QueryDict(''), datastructures.MultiValueDict() 
     118            self._post, self._files = http.QueryDict('', encoding=self._encoding), datastructures.MultiValueDict() 
    119119 
    120120    def _get_request(self): 
     
    126126        if not hasattr(self, '_get'): 
    127127            # The WSGI spec says 'QUERY_STRING' may be absent. 
    128             self._get = http.QueryDict(self.environ.get('QUERY_STRING', '')
     128            self._get = http.QueryDict(self.environ.get('QUERY_STRING', ''), encoding=self._encoding
    129129        return self._get 
    130130 
     
    201201            status_text = 'UNKNOWN STATUS CODE' 
    202202        status = '%s %s' % (response.status_code, status_text) 
    203         response_headers = response.headers.items() 
     203        response_headers = [(str(k), str(v)) for k, v in response.headers.items()] 
    204204        for c in response.cookies.values(): 
    205             response_headers.append(('Set-Cookie', c.output(header=''))) 
     205            response_headers.append(('Set-Cookie', str(c.output(header='')))) 
    206206        start_response(status, response_headers) 
    207207        return response 
  • django/trunk/django/core/mail.py

    r5582 r5609  
    44 
    55from django.conf import settings 
     6from django.utils.encoding import smart_str, force_unicode 
    67from email import Charset, Encoders 
    78from email.MIMEText import MIMEText 
     
    910from email.MIMEBase import MIMEBase 
    1011from email.Header import Header 
    11 from email.Utils import formatdate 
     12from email.Utils import formatdate, parseaddr, formataddr 
    1213import mimetypes 
    1314import os 
     
    6869        if '\n' in val or '\r' in val: 
    6970            raise BadHeaderError, "Header values can't contain newlines (got %r for header %r)" % (val, name) 
    70         if name == "Subject": 
    71             val = Header(val, settings.DEFAULT_CHARSET) 
     71        try: 
     72            val = str(force_unicode(val)) 
     73        except UnicodeEncodeError: 
     74            if name.lower() in ('to', 'from', 'cc'): 
     75                result = [] 
     76                for item in val.split(', '): 
     77                    nm, addr = parseaddr(item) 
     78                    nm = str(Header(nm, settings.DEFAULT_CHARSET)) 
     79                    result.append(formataddr((nm, str(addr)))) 
     80                val = ', '.join(result) 
     81            else: 
     82                val = Header(force_unicode(val), settings.DEFAULT_CHARSET) 
    7283        MIMEText.__setitem__(self, name, val) 
    7384 
     
    7788        if '\n' in val or '\r' in val: 
    7889            raise BadHeaderError, "Header values can't contain newlines (got %r for header %r)" % (val, name) 
    79         if name == "Subject": 
    80             val = Header(val, settings.DEFAULT_CHARSET) 
     90        try: 
     91            val = str(force_unicode(val)) 
     92        except UnicodeEncodeError: 
     93            if name.lower() in ('to', 'from', 'cc'): 
     94                result = [] 
     95                for item in val.split(', '): 
     96                    nm, addr = parseaddr(item) 
     97                    nm = str(Header(nm, settings.DEFAULT_CHARSET)) 
     98                    result.append(formataddr((nm, str(addr)))) 
     99                val = ', '.join(result) 
     100            else: 
     101                val = Header(force_unicode(val), settings.DEFAULT_CHARSET) 
    81102        MIMEMultipart.__setitem__(self, name, val) 
    82103 
     
    177198    def __init__(self, subject='', body='', from_email=None, to=None, bcc=None, 
    178199            connection=None, attachments=None, headers=None): 
     200        """ 
     201        Initialise a single email message (which can be sent to multiple 
     202        recipients). 
     203 
     204        All strings used to create the message can be unicode strings (or UTF-8 
     205        bytestrings). The SafeMIMEText class will handle any necessary encoding 
     206        conversions. 
     207        """ 
    179208        self.to = to or [] 
    180209        self.bcc = bcc or [] 
     
    193222    def message(self): 
    194223        encoding = self.encoding or settings.DEFAULT_CHARSET 
    195         msg = SafeMIMEText(self.body, self.content_subtype, encoding) 
     224        msg = SafeMIMEText(smart_str(self.body, settings.DEFAULT_CHARSET), self.content_subtype, encoding) 
    196225        if self.attachments: 
    197226            body_msg = msg 
  • django/trunk/django/core/management.py

    r5593 r5609  
    428428        if os.path.exists(sql_file): 
    429429            fp = open(sql_file, 'U') 
    430             for statement in statements.split(fp.read()): 
     430            for statement in statements.split(fp.read().decode(settings.FILE_CHARSET)): 
    431431                # Remove any comments from the file 
    432                 statement = re.sub(r"--.*[\n\Z]", "", statement) 
     432                statement = re.sub(ur"--.*[\n\Z]", "", statement) 
    433433                if statement.strip(): 
    434                     output.append(statement + ";") 
     434                    output.append(statement + u";") 
    435435            fp.close() 
    436436 
  • django/trunk/django/core/serializers/base.py

    r5075 r5609  
    88    from StringIO import StringIO 
    99from django.db import models 
     10from django.utils.encoding import smart_str, smart_unicode 
    1011 
    1112class SerializationError(Exception): 
     
    6061        else: 
    6162            value = field.flatten_data(follow=None, obj=obj).get(field.name, "") 
    62         return str(value) 
     63        return smart_unicode(value) 
    6364 
    6465    def start_serialization(self): 
     
    155156 
    156157    def __repr__(self): 
    157         return "<DeserializedObject: %s>" % str(self.object) 
     158        return "<DeserializedObject: %s>" % smart_str(self.object) 
    158159 
    159160    def save(self, save_m2m=True): 
  • django/trunk/django/core/serializers/__init__.py

    r4712 r5609  
    77    >>> json = serializers.serialize("json", some_query_set) 
    88    >>> objects = list(serializers.deserialize("json", json)) 
    9          
     9 
    1010To add your own serializers, use the SERIALIZATION_MODULES setting:: 
    1111 
     
    3131    BUILTIN_SERIALIZERS["yaml"] = "django.core.serializers.pyyaml" 
    3232except ImportError: 
    33     pass     
     33    pass 
    3434 
    3535_serializers = {} 
    36          
     36 
    3737def register_serializer(format, serializer_module): 
    3838    """Register a new serializer by passing in a module name.""" 
    3939    module = __import__(serializer_module, {}, {}, ['']) 
    4040    _serializers[format] = module 
    41      
     41 
    4242def unregister_serializer(format): 
    4343    """Unregister a given serializer""" 
    4444    del _serializers[format] 
    45      
     45 
    4646def get_serializer(format): 
    4747    if not _serializers: 
     
    5353        _load_serializers() 
    5454    return _serializers.keys() 
    55      
     55 
    5656def get_deserializer(format): 
    5757    if not _serializers: 
    5858        _load_serializers() 
    5959    return _serializers[format].Deserializer 
    60      
     60 
    6161def serialize(format, queryset, **options): 
    6262    """ 
  • django/trunk/django/core/serializers/python.py

    r5371 r5609  
    88from django.core.serializers import base 
    99from django.db import models 
     10from django.utils.encoding import smart_unicode 
    1011 
    1112class Serializer(base.Serializer): 
     
    1314    Serializes a QuerySet to basic Python objects. 
    1415    """ 
    15      
     16 
    1617    def start_serialization(self): 
    1718        self._current = None 
    1819        self.objects = [] 
    19          
     20 
    2021    def end_serialization(self): 
    2122        pass 
    22          
     23 
    2324    def start_object(self, obj): 
    2425        self._current = {} 
    25          
     26 
    2627    def end_object(self, obj): 
    2728        self.objects.append({ 
    28             "model"  : str(obj._meta), 
    29             "pk"     : str(obj._get_pk_val()), 
     29            "model"  : smart_unicode(obj._meta), 
     30            "pk"     : smart_unicode(obj._get_pk_val()), 
    3031            "fields" : self._current 
    3132        }) 
    3233        self._current = None 
    33          
     34 
    3435    def handle_field(self, obj, field): 
    3536        self._current[field.name] = getattr(obj, field.name) 
    36          
     37 
    3738    def handle_fk_field(self, obj, field): 
    3839        related = getattr(obj, field.name) 
     
    4546                related = getattr(related, field.rel.field_name) 
    4647        self._current[field.name] = related 
    47      
     48 
    4849    def handle_m2m_field(self, obj, field): 
    4950        self._current[field.name] = [related._get_pk_val() for related in getattr(obj, field.name).iterator()] 
    50      
     51 
    5152    def getvalue(self): 
    5253        return self.objects 
     
    5556    """ 
    5657    Deserialize simple Python objects back into Django ORM instances. 
    57      
     58 
    5859    It's expected that you pass the Python objects themselves (instead of a 
    5960    stream or a string) to the constructor 
     
    6566        data = {Model._meta.pk.attname : Model._meta.pk.to_python(d["pk"])} 
    6667        m2m_data = {} 
    67          
     68 
    6869        # Handle each field 
    6970        for (field_name, field_value) in d["fields"].iteritems(): 
    70             if isinstance(field_value, unicode): 
    71                 field_value = field_value.encode(options.get("encoding", settings.DEFAULT_CHARSET)
    72                  
     71            if isinstance(field_value, str): 
     72                field_value = smart_unicode(field_value, options.get("encoding", settings.DEFAULT_CHARSET), strings_only=True
     73 
    7374            field = Model._meta.get_field(field_name) 
    74              
     75 
    7576            # Handle M2M relations 
    7677            if field.rel and isinstance(field.rel, models.ManyToManyRel): 
    77                 pks = [] 
    7878                m2m_convert = field.rel.to._meta.pk.to_python 
    79                 for pk in field_value: 
    80                     if isinstance(pk, unicode): 
    81                         pks.append(m2m_convert(pk.encode(options.get("encoding", settings.DEFAULT_CHARSET)))) 
    82                     else: 
    83                         pks.append(m2m_convert(pk)) 
    84                 m2m_data[field.name] = pks 
    85                  
     79                m2m_data[field.name] = [m2m_convert(smart_unicode(pk)) for pk in field_value] 
     80 
    8681            # Handle FK fields 
    8782            elif field.rel and isinstance(field.rel, models.ManyToOneRel): 
     
    9085                else: 
    9186                    data[field.attname] = None 
    92                      
     87 
    9388            # Handle all other fields 
    9489            else: 
    9590                data[field.name] = field.to_python(field_value) 
    96                  
     91 
    9792        yield base.DeserializedObject(Model(**data), m2m_data) 
    9893 
     
    106101        Model = None 
    107102    if Model is None: 
    108         raise base.DeserializationError("Invalid model identifier: '%s'" % model_identifier) 
     103        raise base.DeserializationError(u"Invalid model identifier: '%s'" % model_identifier) 
    109104    return Model 
  • django/trunk/django/core/serializers/pyyaml.py

    r5409 r5609  
    2222        self.options.pop('fields', None) 
    2323        yaml.dump(self.objects, self.stream, **self.options) 
    24          
     24 
    2525    def getvalue(self): 
    2626        return self.stream.getvalue() 
     
    3636    for obj in PythonDeserializer(yaml.load(stream)): 
    3737        yield obj 
    38          
     38 
  • django/trunk/django/core/serializers/xml_serializer.py

    r5371 r5609  
    77from django.db import models 
    88from django.utils.xmlutils import SimplerXMLGenerator 
     9from django.utils.encoding import smart_unicode 
    910from xml.dom import pulldom 
    1011 
     
    1314    Serializes a QuerySet to XML. 
    1415    """ 
    15      
     16 
    1617    def indent(self, level): 
    1718        if self.options.get('indent', None) is not None: 
     
    2526        self.xml.startDocument() 
    2627        self.xml.startElement("django-objects", {"version" : "1.0"}) 
    27          
     28 
    2829    def end_serialization(self): 
    2930        """ 
     
    3334        self.xml.endElement("django-objects") 
    3435        self.xml.endDocument() 
    35          
     36 
    3637    def start_object(self, obj): 
    3738        """ 
     
    4041        if not hasattr(obj, "_meta"): 
    4142            raise base.SerializationError("Non-model object (%s) encountered during serialization" % type(obj)) 
    42              
     43 
    4344        self.indent(1) 
    4445        self.xml.startElement("object", { 
    45             "pk"    : str(obj._get_pk_val()), 
    46             "model" : str(obj._meta), 
     46            "pk"    : smart_unicode(obj._get_pk_val()), 
     47            "model" : smart_unicode(obj._meta), 
    4748        }) 
    48          
     49 
    4950    def end_object(self, obj): 
    5051        """ 
     
    5354        self.indent(1) 
    5455        self.xml.endElement("object") 
    55          
     56 
    5657    def handle_field(self, obj, field): 
    5758        """ 
     
    6465            "type" : field.get_internal_type() 
    6566        }) 
    66          
     67 
    6768        # Get a "string version" of the object's data (this is handled by the 
    68         # serializer base class).  
     69        # serializer base class). 
    6970        if getattr(obj, field.name) is not None: 
    7071            value = self.get_string_value(obj, field) 
    71             self.xml.characters(str(value)) 
     72            self.xml.characters(smart_unicode(value)) 
    7273        else: 
    7374            self.xml.addQuickElement("None") 
    7475 
    7576        self.xml.endElement("field") 
    76          
     77 
    7778    def handle_fk_field(self, obj, field): 
    7879        """ 
     
    8990                # Related to remote object via other field 
    9091                related = getattr(related, field.rel.field_name) 
    91             self.xml.characters(str(related)) 
     92            self.xml.characters(smart_unicode(related)) 
    9293        else: 
    9394            self.xml.addQuickElement("None") 
    9495        self.xml.endElement("field") 
    95      
     96 
    9697    def handle_m2m_field(self, obj, field): 
    9798        """ 
     
    102103        self._start_relational_field(field) 
    103104        for relobj in getattr(obj, field.name).iterator(): 
    104             self.xml.addQuickElement("object", attrs={"pk" : str(relobj._get_pk_val())}) 
     105            self.xml.addQuickElement("object", attrs={"pk" : smart_unicode(relobj._get_pk_val())}) 
    105106        self.xml.endElement("field") 
    106          
     107 
    107108    def _start_relational_field(self, field): 
    108109        """ 
     
    113114            "name" : field.name, 
    114115            "rel"  : field.rel.__class__.__name__, 
    115             "to"   : str(field.rel.to._meta), 
     116            "to"   : smart_unicode(field.rel.to._meta), 
    116117        }) 
    117          
     118 
    118119class Deserializer(base.Deserializer): 
    119120    """ 
    120121    Deserialize XML. 
    121122    """ 
    122      
     123 
    123124    def __init__(self, stream_or_string, **options): 
    124125        super(Deserializer, self).__init__(stream_or_string, **options) 
    125         self.encoding = self.options.get("encoding", settings.DEFAULT_CHARSET) 
    126         self.event_stream = pulldom.parse(self.stream)  
    127      
     126        self.event_stream = pulldom.parse(self.stream) 
     127 
    128128    def next(self): 
    129129        for event, node in self.event_stream: 
     
    132132                return self._handle_object(node) 
    133133        raise StopIteration 
    134          
     134 
    135135    def _handle_object(self, node): 
    136136        """ 
    137137        Convert an <object> node to a DeserializedObject. 
    138138        """ 
    139         # Look up the model using the model loading mechanism. If this fails, bail. 
     139        # Look up the model using the model loading mechanism. If this fails, 
     140        # bail. 
    140141        Model = self._get_model_from_node(node, "model") 
    141          
     142 
    142143        # Start building a data dictionary from the object.  If the node is 
    143144        # missing the pk attribute, bail. 
     
    147148 
    148149        data = {Model._meta.pk.attname : Model._meta.pk.to_python(pk)} 
    149          
     150 
    150151        # Also start building a dict of m2m data (this is saved as 
    151152        # {m2m_accessor_attribute : [list_of_related_objects]}) 
    152153        m2m_data = {} 
    153          
     154 
    154155        # Deseralize each field. 
    155156        for field_node in node.getElementsByTagName("field"): 
     
    159160            if not field_name: 
    160161                raise base.DeserializationError("<field> node is missing the 'name' attribute") 
    161              
     162 
    162163            # Get the field from the Model. This will raise a 
    163164            # FieldDoesNotExist if, well, the field doesn't exist, which will 
    164165            # be propagated correctly. 
    165166            field = Model._meta.get_field(field_name) 
    166              
     167 
    167168            # As is usually the case, relation fields get the special treatment. 
    168169            if field.rel and isinstance(field.rel, models.ManyToManyRel): 
     
    174175                    value = None 
    175176                else: 
    176                     value = field.to_python(getInnerText(field_node).strip().encode(self.encoding)
     177                    value = field.to_python(getInnerText(field_node).strip()
    177178                data[field.name] = value 
    178          
     179 
    179180        # Return a DeserializedObject so that the m2m data has a place to live. 
    180181        return base.DeserializedObject(Model(**data), m2m_data) 
    181          
     182 
    182183    def _handle_fk_field_node(self, node, field): 
    183184        """ 
     
    189190        else: 
    190191            return field.rel.to._meta.get_field(field.rel.field_name).to_python( 
    191                        getInnerText(node).strip().encode(self.encoding)
    192          
     192                       getInnerText(node).strip()
     193 
    193194    def _handle_m2m_field_node(self, node, field): 
    194195        """ 
    195         Handle a <field> node for a ManyToManyField 
     196        Handle a <field> node for a ManyToManyField. 
    196197        """ 
    197198        return [field.rel.to._meta.pk.to_python( 
    198                     c.getAttribute("pk").encode(self.encoding))  
     199                    c.getAttribute("pk")) 
    199200                    for c in node.getElementsByTagName("object")] 
    200      
     201 
    201202    def _get_model_from_node(self, node, attr): 
    202203        """ 
     
    218219                    (node.nodeName, model_identifier)) 
    219220        return Model 
    220          
    221      
     221 
     222 
    222223def getInnerText(node): 
    223224    """ 
     
    233234        else: 
    234235           pass 
    235     return "".join(inner_text) 
     236    return u"".join(inner_text) 
     237 
  • django/trunk/django/core/urlresolvers.py

    r5538 r5609  
    1010from django.http import Http404 
    1111from django.core.exceptions import ImproperlyConfigured, ViewDoesNotExist 
     12from django.utils.encoding import iri_to_uri 
    1213from django.utils.functional import memoize 
    1314import re 
     
    3839    during the import fail and the string is returned. 
    3940    """ 
    40     if not callable(lookup_view): 
    41         mod_name, func_name = get_mod_func(lookup_view) 
    42         try: 
    43             if func_name != '': 
    44                 lookup_view = getattr(__import__(mod_name, {}, {}, ['']), func_name) 
    45         except (ImportError, AttributeError): 
    46             if not can_fail: 
    47                 raise 
     41    try: 
     42        # Bail out early if lookup_view is not ASCII. This can't be a function. 
     43        lookup_view = lookup_view.encode('ascii') 
     44 
     45        if not callable(lookup_view): 
     46            mod_name, func_name = get_mod_func(lookup_view) 
     47            try: 
     48                if func_name != '': 
     49                    lookup_view = getattr(__import__(mod_name, {}, {}, ['']), func_name) 
     50            except (ImportError, AttributeError): 
     51                if not can_fail: 
     52                    raise 
     53    except UnicodeEncodeError: 
     54        pass 
    4855    return lookup_view 
    4956get_callable = memoize(get_callable, _callable_cache) 
     
    266273            raise NoReverseMatch 
    267274        if lookup_view in self.reverse_dict: 
    268             return ''.join([reverse_helper(part.regex, *args, **kwargs) for part in self.reverse_dict[lookup_view]]) 
     275            return u''.join([reverse_helper(part.regex, *args, **kwargs) for part in self.reverse_dict[lookup_view]]) 
    269276        raise NoReverseMatch 
    270277 
     
    280287    args = args or [] 
    281288    kwargs = kwargs or {} 
    282     return '/' + get_resolver(urlconf).reverse(viewname, *args, **kwargs
    283  
     289    return iri_to_uri(u'/' + get_resolver(urlconf).reverse(viewname, *args, **kwargs)
     290 
  • django/trunk/django/core/validators.py

    r5302 r5609  
    1111import urllib2 
    1212from django.conf import settings 
    13 from django.utils.translation import gettext, gettext_lazy, ngettext 
     13from django.utils.translation import ugettext as _, ugettext_lazy, ungettext 
    1414from django.utils.functional import Promise, lazy 
     15from django.utils.encoding import force_unicode 
    1516import re 
    1617 
     
    3334url_re = re.compile(r'^https?://\S+$') 
    3435 
    35 lazy_inter = lazy(lambda a,b: str(a) % b, str
     36lazy_inter = lazy(lambda a,b: force_unicode(a) % b, unicode
    3637 
    3738class ValidationError(Exception): 
     
    3940        "ValidationError can be passed a string or a list." 
    4041        if isinstance(message, list): 
    41             self.messages = message 
     42            self.messages = [force_unicode(msg) for msg in message] 
    4243        else: 
    4344            assert isinstance(message, (basestring, Promise)), ("%s should be a string" % repr(message)) 
    44             self.messages = [message] 
     45            self.messages = [force_unicode(message)] 
     46 
    4547    def __str__(self): 
    4648        # This is needed because, without a __str__(), printing an exception 
     
    5456        "ValidationError can be passed a string or a list." 
    5557        if isinstance(message, list): 
    56             self.messages = message 
     58            self.messages = [force_unicode(msg) for msg in message] 
    5759        else: 
    5860            assert isinstance(message, (basestring, Promise)), ("'%s' should be a string" % message) 
    59             self.messages = [message] 
     61            self.messages = [force_unicode(message)] 
     62 
    6063    def __str__(self): 
    6164        return str(self.messages) 
     
    6366def isAlphaNumeric(field_data, all_data): 
    6467    if not alnum_re.search(field_data): 
    65         raise ValidationError, gettext("This value must contain only letters, numbers and underscores.") 
     68        raise ValidationError, _("This value must contain only letters, numbers and underscores.") 
    6669 
    6770def isAlphaNumericURL(field_data, all_data): 
    6871    if not alnumurl_re.search(field_data): 
    69         raise ValidationError, gettext("This value must contain only letters, numbers, underscores, dashes or slashes.") 
     72        raise ValidationError, _("This value must contain only letters, numbers, underscores, dashes or slashes.") 
    7073 
    7174def isSlug(field_data, all_data): 
    7275    if not slug_re.search(field_data): 
    73         raise ValidationError, gettext("This value must contain only letters, numbers, underscores or hyphens.") 
     76        raise ValidationError, _("This value must contain only letters, numbers, underscores or hyphens.") 
    7477 
    7578def isLowerCase(field_data, all_data): 
    7679    if field_data.lower() != field_data: 
    77         raise ValidationError, gettext("Uppercase letters are not allowed here.") 
     80        raise ValidationError, _("Uppercase letters are not allowed here.") 
    7881 
    7982def isUpperCase(field_data, all_data): 
    8083    if field_data.upper() != field_data: 
    81         raise ValidationError, gettext("Lowercase letters are not allowed here.") 
     84        raise ValidationError, _("Lowercase letters are not allowed here.") 
    8285 
    8386def isCommaSeparatedIntegerList(field_data, all_data): 
     
    8689            int(supposed_int) 
    8790        except ValueError: 
    88             raise ValidationError, gettext("Enter only digits separated by commas.") 
     91            raise ValidationError, _("Enter only digits separated by commas.") 
    8992 
    9093def isCommaSeparatedEmailList(field_data, all_data): 
     
    98101            isValidEmail(supposed_email.strip(), '') 
    99102        except ValidationError: 
    100             raise ValidationError, gettext("Enter valid e-mail addresses separated by commas.") 
     103            raise ValidationError, _("Enter valid e-mail addresses separated by commas.") 
    101104 
    102105def isValidIPAddress4(field_data, all_data): 
    103106    if not ip4_re.search(field_data): 
    104         raise ValidationError, gettext("Please enter a valid IP address.") 
     107        raise ValidationError, _("Please enter a valid IP address.") 
    105108 
    106109def isNotEmpty(field_data, all_data): 
    107110    if field_data.strip() == '': 
    108         raise ValidationError, gettext("Empty values are not allowed here.") 
     111        raise ValidationError, _("Empty values are not allowed here.") 
    109112 
    110113def isOnlyDigits(field_data, all_data): 
    111114    if not field_data.isdigit(): 
    112         raise ValidationError, gettext("Non-numeric characters aren't allowed here.") 
     115        raise ValidationError, _("Non-numeric characters aren't allowed here.") 
    113116 
    114117def isNotOnlyDigits(field_data, all_data): 
    115118    if field_data.isdigit(): 
    116         raise ValidationError, gettext("This value can't be comprised solely of digits.") 
     119        raise ValidationError, _("This value can't be comprised solely of digits.") 
    117120 
    118121def isInteger(field_data, all_data): 
    119122    # This differs from isOnlyDigits because this accepts the negative sign 
    120123    if not integer_re.search(field_data): 
    121         raise ValidationError, gettext("Enter a whole number.") 
     124        raise ValidationError, _("Enter a whole number.") 
    122125 
    123126def isOnlyLetters(field_data, all_data): 
    124127    if not field_data.isalpha(): 
    125         raise ValidationError, gettext("Only alphabetical characters are allowed here.") 
     128        raise ValidationError, _("Only alphabetical characters are allowed here.") 
    126129 
    127130def _isValidDate(date_string): 
     
    138141    # value to the database, and strftime requires that the year be >=1900. 
    139142    if year < 1900: 
    140         raise ValidationError, gettext('Year must be 1900 or later.') 
     143        raise ValidationError, _('Year must be 1900 or later.') 
    141144    try: 
    142145        date(year, month, day) 
    143146    except ValueError, e: 
    144         msg = gettext('Invalid date: %s') % gettext(str(e)) 
     147        msg = _('Invalid date: %s') % _(str(e)) 
    145148        raise ValidationError, msg     
    146149 
    147150def isValidANSIDate(field_data, all_data): 
    148151    if not ansi_date_re.search(field_data): 
    149         raise ValidationError, gettext('Enter a valid date in YYYY-MM-DD format.') 
     152        raise ValidationError, _('Enter a valid date in YYYY-MM-DD format.') 
    150153    _isValidDate(field_data) 
    151154 
    152155def isValidANSITime(field_data, all_data): 
    153156    if not ansi_time_re.search(field_data): 
    154         raise ValidationError, gettext('Enter a valid time in HH:MM format.') 
     157        raise ValidationError, _('Enter a valid time in HH:MM format.') 
    155158 
    156159def isValidANSIDatetime(field_data, all_data): 
    157160    if not ansi_datetime_re.search(field_data): 
    158         raise ValidationError, gettext('Enter a valid date/time in YYYY-MM-DD HH:MM format.') 
     161        raise ValidationError, _('Enter a valid date/time in YYYY-MM-DD HH:MM format.') 
    159162    _isValidDate(field_data.split()[0]) 
    160163 
    161164def isValidEmail(field_data, all_data): 
    162165    if not email_re.search(field_data): 
    163         raise ValidationError, gettext('Enter a valid e-mail address.') 
     166        raise ValidationError, _('Enter a valid e-mail address.') 
    164167 
    165168def isValidImage(field_data, all_data): 
     
    173176        content = field_data['content'] 
    174177    except TypeError: 
    175         raise ValidationError, gettext("No file was submitted. Check the encoding type on the form.") 
     178        raise ValidationError, _("No file was submitted. Check the encoding type on the form.") 
    176179    try: 
    177180        Image.open(StringIO(content)) 
    178181    except IOError: # Python Imaging Library doesn't recognize it as an image 
    179         raise ValidationError, gettext("Upload a valid image. The file you uploaded was either not an image or a corrupted image.") 
     182        raise ValidationError, _("Upload a valid image. The file you uploaded was either not an image or a corrupted image.") 
    180183 
    181184def isValidImageURL(field_data, all_data): 
     
    184187        uc(field_data, all_data) 
    185188    except URLMimeTypeCheck.InvalidContentType: 
    186         raise ValidationError, gettext("The URL %s does not point to a valid image.") % field_data 
     189        raise ValidationError, _("The URL %s does not point to a valid image.") % field_data 
    187190 
    188191def isValidPhone(field_data, all_data): 
    189192    if not phone_re.search(field_data): 
    190         raise ValidationError, gettext('Phone numbers must be in XXX-XXX-XXXX format. "%s" is invalid.') % field_data 
     193        raise ValidationError, _('Phone numbers must be in XXX-XXX-XXXX format. "%s" is invalid.') % field_data 
    191194 
    192195def isValidQuicktimeVideoURL(field_data, all_data): 
     
    196199        uc(field_data, all_data) 
    197200    except URLMimeTypeCheck.InvalidContentType: 
    198         raise ValidationError, gettext("The URL %s does not point to a valid QuickTime video.") % field_data 
     201        raise ValidationError, _("The URL %s does not point to a valid QuickTime video.") % field_data 
    199202 
    200203def isValidURL(field_data, all_data): 
    201204    if not url_re.search(field_data): 
    202         raise ValidationError, gettext("A valid URL is required.") 
     205        raise ValidationError, _("A valid URL is required.") 
    203206 
    204207def isValidHTML(field_data, all_data): 
     
    214217    from xml.dom.minidom import parseString 
    215218    error_messages = [e.firstChild.wholeText for e in parseString(u.read()).getElementsByTagName('messages')[0].getElementsByTagName('msg')] 
    216     raise ValidationError, gettext("Valid HTML is required. Specific errors are:\n%s") % "\n".join(error_messages) 
     219    raise ValidationError, _("Valid HTML is required. Specific errors are:\n%s") % "\n".join(error_messages) 
    217220 
    218221def isWellFormedXml(field_data, all_data): 
     
    221224        parseString(field_data) 
    222225    except Exception, e: # Naked except because we're not sure what will be thrown 
    223         raise ValidationError, gettext("Badly formed XML: %s") % str(e) 
     226        raise ValidationError, _("Badly formed XML: %s") % str(e) 
    224227 
    225228def isWellFormedXmlFragment(field_data, all_data): 
     
    251254    states = ['AA', 'AE', 'AK', 'AL', 'AP', 'AR', 'AS', 'AZ', 'CA', 'CO', 'CT', 'DC', 'DE', 'FL', 'FM', 'GA', 'GU', 'HI', 'IA', 'ID', 'IL', 'IN', 'KS', 'KY', 'LA', 'MA', 'MD', 'ME', 'MH', 'MI', 'MN', 'MO', 'MP', 'MS', 'MT', 'NC', 'ND', 'NE', 'NH', 'NJ', 'NM', 'NV', 'NY', 'OH', 'OK', 'OR', 'PA', 'PR', 'PW', 'RI', 'SC', 'SD', 'TN', 'TX', 'UT', 'VA', 'VI', 'VT', 'WA', 'WI', 'WV', 'WY'] 
    252255    if field_data.upper() not in states: 
    253         raise ValidationError, gettext("Enter a valid U.S. state abbreviation.") 
     256        raise ValidationError, _("Enter a valid U.S. state abbreviation.") 
    254257 
    255258def hasNoProfanities(field_data, all_data): 
     
    265268        from django.utils.text import get_text_list 
    266269        plural = len(words_seen) > 1 
    267         raise ValidationError, ngettext("Watch your mouth! The word %s is not allowed here.", 
     270        raise ValidationError, ungettext("Watch your mouth! The word %s is not allowed here.", 
    268271            "Watch your mouth! The words %s are not allowed here.", plural) % \ 
    269272            get_text_list(['"%s%s%s"' % (i[0], '-'*(len(i)-2), i[-1]) for i in words_seen], 'and') 
     
    272275    def __init__(self, other_field_name, error_message=None): 
    273276        self.other = other_field_name 
    274         self.error_message = error_message or lazy_inter(gettext_lazy("This field must match the '%s' field."), self.other) 
     277        self.error_message = error_message or lazy_inter(ugettext_lazy("This field must match the '%s' field."), self.other) 
    275278        self.always_test = True 
    276279 
     
    291294 
    292295class RequiredIfOtherFieldNotGiven(object): 
    293     def __init__(self, other_field_name, error_message=gettext_lazy("Please enter something for at least one field.")): 
     296    def __init__(self, other_field_name, error_message=ugettext_lazy("Please enter something for at least one field.")): 
    294297        self.other, self.error_message = other_field_name, error_message 
    295298        self.always_test = True 
     
    300303 
    301304class RequiredIfOtherFieldsGiven(object): 
    302     def __init__(self, other_field_names, error_message=gettext_lazy("Please enter both fields or leave them both empty.")): 
     305    def __init__(self, other_field_names, error_message=ugettext_lazy("Please enter both fields or leave them both empty.")): 
    303306        self.other, self.error_message = other_field_names, error_message 
    304307        self.always_test = True 
     
    311314class RequiredIfOtherFieldGiven(RequiredIfOtherFieldsGiven): 
    312315    "Like RequiredIfOtherFieldsGiven, but takes a single field name instead of a list." 
    313     def __init__(self, other_field_name, error_message=gettext_lazy("Please enter both fields or leave them both empty.")): 
     316    def __init__(self, other_field_name, error_message=ugettext_lazy("Please enter both fields or leave them both empty.")): 
    314317        RequiredIfOtherFieldsGiven.__init__(self, [other_field_name], error_message) 
    315318 
     
    319322        self.other_value = other_value 
    320323        other_label = other_label or other_value 
    321         self.error_message = error_message or lazy_inter(gettext_lazy("This field must be given if %(field)s is %(value)s"), { 
     324        self.error_message = error_message or lazy_inter(ugettext_lazy("This field must be given if %(field)s is %(value)s"), { 
    322325            'field': other_field, 'value': other_label}) 
    323326        self.always_test = True 
     
    332335        self.other_value = other_value 
    333336        other_label = other_label or other_value 
    334         self.error_message = error_message or lazy_inter(gettext_lazy("This field must be given if %(field)s is not %(value)s"), { 
     337        self.error_message = error_message or lazy_inter(ugettext_lazy("This field must be given if %(field)s is not %(value)s"), { 
    335338            'field': other_field, 'value': other_label}) 
    336339        self.always_test = True 
     
    351354    def __init__(self, field_name, prefix, error_message): 
    352355        self.field_name, self.prefix = field_name, prefix 
    353         self.error_message = error_message or gettext_lazy("Duplicate values are not allowed.") 
     356        self.error_message = error_message or ugettext_lazy("Duplicate values are not allowed.") 
    354357 
    355358    def __call__(self, field_data, all_data): 
     
    366369        if not error_message: 
    367370            if lower and upper: 
    368                  self.error_message = gettext("This value must be between %(lower)s and %(upper)s.") % {'lower': lower, 'upper': upper} 
     371                 self.error_message = _("This value must be between %(lower)s and %(upper)s.") % {'lower': lower, 'upper': upper} 
    369372            elif lower: 
    370                 self.error_message = gettext("This value must be at least %s.") % lower 
     373                self.error_message = _("This value must be at least %s.") % lower 
    371374            elif upper: 
    372                 self.error_message = gettext("This value must be no more than %s.") % upper 
     375                self.error_message = _("This value must be no more than %s.") % upper 
    373376        else: 
    374377            self.error_message = error_message 
     
    406409        val = log(int(field_data)) / log(self.power_of) 
    407410        if val != int(val): 
    408             raise ValidationError, gettext("This value must be a power of %s.") % self.power_of 
     411            raise ValidationError, _("This value must be a power of %s.") % self.power_of 
    409412 
    410413class IsValidDecimal(object): 
     
    415418        match = decimal_re.search(str(field_data)) 
    416419        if not match: 
    417             raise ValidationError, gettext("Please enter a valid decimal number.") 
     420            raise ValidationError, _("Please enter a valid decimal number.") 
    418421         
    419422        digits = len(match.group('digits') or '') 
     
    421424         
    422425        if digits + decimals > self.max_digits: 
    423             raise ValidationError, ngettext("Please enter a valid decimal number with at most %s total digit.", 
     426            raise ValidationError, ungettext("Please enter a valid decimal number with at most %s total digit.", 
    424427                "Please enter a valid decimal number with at most %s total digits.", self.max_digits) % self.max_digits 
    425428        if digits > (self.max_digits - self.decimal_places): 
    426             raise ValidationError, ngettext( "Please enter a valid decimal number with a whole part of at most %s digit.", 
     429            raise ValidationError, ungettext( "Please enter a valid decimal number with a whole part of at most %s digit.", 
    427430                "Please enter a valid decimal number with a whole part of at most %s digits.", str(self.max_digits-self.decimal_places)) % str(self.max_digits-self.decimal_places) 
    428431        if decimals > self.decimal_places: 
    429             raise ValidationError, ngettext("Please enter a valid decimal number with at most %s decimal place.", 
     432            raise ValidationError, ungettext("Please enter a valid decimal number with at most %s decimal place.", 
    430433                "Please enter a valid decimal number with at most %s decimal places.", self.decimal_places) % self.decimal_places 
    431434 
     
    435438        float(data) 
    436439    except ValueError: 
    437         raise ValidationError, gettext("Please enter a valid floating point number.") 
     440        raise ValidationError, ugettext("Please enter a valid floating point number.") 
    438441 
    439442class HasAllowableSize(object): 
     
    444447    def __init__(self, min_size=None, max_size=None, min_error_message=None, max_error_message=None): 
    445448        self.min_size, self.max_size = min_size, max_size 
    446         self.min_error_message = min_error_message or lazy_inter(gettext_lazy("Make sure your uploaded file is at least %s bytes big."), min_size) 
    447         self.max_error_message = max_error_message or lazy_inter(gettext_lazy("Make sure your uploaded file is at most %s bytes big."), max_size) 
     449        self.min_error_message = min_error_message or lazy_inter(ugettext_lazy("Make sure your uploaded file is at least %s bytes big."), min_size) 
     450        self.max_error_message = max_error_message or lazy_inter(ugettext_lazy("Make sure your uploaded file is at most %s bytes big."), max_size) 
    448451 
    449452    def __call__(self, field_data, all_data): 
     
    451454            content = field_data['content'] 
    452455        except TypeError: 
    453             raise ValidationError, gettext_lazy("No file was submitted. Check the encoding type on the form.") 
     456            raise ValidationError, ugettext_lazy("No file was submitted. Check the encoding type on the form.") 
    454457        if self.min_size is not None and len(content) < self.min_size: 
    455458            raise ValidationError, self.min_error_message 
     
    462465    should be in string format, not already compiled. 
    463466    """ 
    464     def __init__(self, regexp, error_message=gettext_lazy("The format for this field is wrong.")): 
     467    def __init__(self, regexp, error_message=ugettext_lazy("The format for this field is wrong.")): 
    465468        self.regexp = re.compile(regexp) 
    466469        self.error_message = error_message 
     
    477480    specify one on instantiation. 
    478481    """ 
    479     def __init__(self, validator_list=None, error_message=gettext_lazy("This field is invalid.")): 
     482    def __init__(self, validator_list=None, error_message=ugettext_lazy("This field is invalid.")): 
    480483        if validator_list is None: validator_list = [] 
    481484        self.validator_list = validator_list 
     
    513516            info = urllib2.urlopen(field_data).info() 
    514517        except (urllib2.HTTPError, urllib2.URLError): 
    515             raise URLMimeTypeCheck.CouldNotRetrieve, gettext("Could not retrieve anything from %s.") % field_data 
     518            raise URLMimeTypeCheck.CouldNotRetrieve, _("Could not retrieve anything from %s.") % field_data 
    516519        content_type = info['content-type'] 
    517520        if content_type not in self.mime_type_list: 
    518             raise URLMimeTypeCheck.InvalidContentType, gettext("The URL %(url)s returned the invalid Content-Type header '%(contenttype)s'.") % { 
     521            raise URLMimeTypeCheck.InvalidContentType, _("The