From 0e2043deefc517baed2e58b591e1c24275dc63d7 Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Wed, 16 May 2007 12:51:18 +0000 Subject: [PATCH] unicode: Fixed a couple of potential unicode problems in auth module. git-svn-id: http://code.djangoproject.com/svn/django/branches/unicode@5256 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/contrib/auth/management.py | 4 ++-- django/contrib/auth/models.py | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/django/contrib/auth/management.py b/django/contrib/auth/management.py index 3f52681747..2b4cb8bd19 100644 --- a/django/contrib/auth/management.py +++ b/django/contrib/auth/management.py @@ -7,13 +7,13 @@ from django.db.models import get_models, signals from django.contrib.auth import models as auth_app def _get_permission_codename(action, opts): - return '%s_%s' % (action, opts.object_name.lower()) + return u'%s_%s' % (action, opts.object_name.lower()) def _get_all_permissions(opts): "Returns (codename, name) for all permissions in the given opts." perms = [] for action in ('add', 'change', 'delete'): - perms.append((_get_permission_codename(action, opts), 'Can %s %s' % (action, opts.verbose_name))) + perms.append((_get_permission_codename(action, opts), u'Can %s %s' % (action, opts.verbose_name_raw))) return perms + list(opts.permissions) def create_permissions(app, created_models, verbosity): diff --git a/django/contrib/auth/models.py b/django/contrib/auth/models.py index 6137b52baf..a6e11a162d 100644 --- a/django/contrib/auth/models.py +++ b/django/contrib/auth/models.py @@ -4,6 +4,7 @@ from django.db import backend, connection, models from django.contrib.contenttypes.models import ContentType from django.utils.translation import ugettext_lazy, ugettext as _ import datetime +import urllib def check_password(raw_password, enc_password): """ @@ -132,7 +133,7 @@ class User(models.Model): return self.username def get_absolute_url(self): - return "/users/%s/" % self.username + return "/users/%s/" % urllib.quote(smart_str(self.username)) def is_anonymous(self): "Always returns False. This is a way of comparing User objects to anonymous users." @@ -145,7 +146,7 @@ class User(models.Model): def get_full_name(self): "Returns the first_name plus the last_name, with a space in between." - full_name = '%s %s' % (self.first_name, self.last_name) + full_name = u'%s %s' % (self.first_name, self.last_name) return full_name.strip() def set_password(self, raw_password): @@ -206,7 +207,7 @@ class User(models.Model): def get_all_permissions(self): if not hasattr(self, '_perm_cache'): import sets - self._perm_cache = sets.Set(["%s.%s" % (p.content_type.app_label, p.codename) for p in self.user_permissions.select_related()]) + self._perm_cache = sets.Set([u"%s.%s" % (p.content_type.app_label, p.codename) for p in self.user_permissions.select_related()]) self._perm_cache.update(self.get_group_permissions()) return self._perm_cache