From patchwork Sat Jan 15 11:16:21 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dirk Wallenstein X-Patchwork-Id: 79045 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bilbo.ozlabs.org (localhost [127.0.0.1]) by ozlabs.org (Postfix) with ESMTP id 67315B70AF for ; Sat, 15 Jan 2011 22:16:41 +1100 (EST) Received: from mailout10.t-online.de (mailout10.t-online.de [194.25.134.21]) by ozlabs.org (Postfix) with ESMTP id 0BCFFB6EF1 for ; Sat, 15 Jan 2011 22:16:39 +1100 (EST) Received: from fwd08.aul.t-online.de (fwd08.aul.t-online.de ) by mailout10.t-online.de with smtp id 1Pe47X-0005lS-Gy; Sat, 15 Jan 2011 12:16:35 +0100 Received: from localhost.localdomain (TvveIeZQrh6FkrZWfu-PdlaCoybEy5-72EIsidYib4LCDAJDSfb8wCjvOpRVBB7Z55@[84.139.70.41]) by fwd08.t-online.de with esmtp id 1Pe47L-1aDD0K0; Sat, 15 Jan 2011 12:16:23 +0100 From: Dirk Wallenstein To: patchwork@lists.ozlabs.org Subject: [PATCH] Implement __unicode__ in models instead of __str__ Date: Sat, 15 Jan 2011 12:16:21 +0100 Message-Id: <1295090181-12195-1-git-send-email-halsmit@t-online.de> X-Mailer: git-send-email 1.7.3.2 X-ID: TvveIeZQrh6FkrZWfu-PdlaCoybEy5-72EIsidYib4LCDAJDSfb8wCjvOpRVBB7Z55 X-TOI-MSGID: 51e3d973-5c29-4034-a847-d415bfe5525d X-BeenThere: patchwork@lists.ozlabs.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Patchwork development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org According to the Django documentation at [1] it is recommended to implement __unicode__ and not __str__. Django's model base class provides a __str__ method that will use the __unicode__ method and convert to utf-8. Also, every text value returned from the DB through the model is unicode. It is now possible to edit Patches and Persons that have values with non-ASCII characters through the admin interface. [1] http://docs.djangoproject.com/en/1.2/ref/unicode/ Signed-off-by: Dirk Wallenstein --- apps/patchwork/models.py | 14 +++++++------- 1 files changed, 7 insertions(+), 7 deletions(-) diff --git a/apps/patchwork/models.py b/apps/patchwork/models.py index 6842622..5c0ca95 100644 --- a/apps/patchwork/models.py +++ b/apps/patchwork/models.py @@ -47,9 +47,9 @@ class Person(models.Model): name = models.CharField(max_length=255, null = True) user = models.ForeignKey(User, null = True) - def __str__(self): + def __unicode__(self): if self.name: - return '%s <%s>' % (self.name, self.email) + return u'%s <%s>' % (self.name, self.email) else: return self.email @@ -66,7 +66,7 @@ class Project(models.Model): listid = models.CharField(max_length=255, unique=True) listemail = models.CharField(max_length=200) - def __str__(self): + def __unicode__(self): return self.name class UserProfile(models.Model): @@ -84,7 +84,7 @@ class UserProfile(models.Model): def name(self): if self.user.first_name or self.user.last_name: names = filter(bool, [self.user.first_name, self.user.last_name]) - return ' '.join(names) + return u' '.join(names) return self.user.username def contributor_projects(self): @@ -129,7 +129,7 @@ class UserProfile(models.Model): person.link_to_user(self.user) person.save() - def __str__(self): + def __unicode__(self): return self.name() class State(models.Model): @@ -137,7 +137,7 @@ class State(models.Model): ordering = models.IntegerField(unique = True) action_required = models.BooleanField(default = True) - def __str__(self): + def __unicode__(self): return self.name class Meta: @@ -193,7 +193,7 @@ class Patch(models.Model): commit_ref = models.CharField(max_length=255, null = True, blank = True) hash = HashField(null = True, db_index = True) - def __str__(self): + def __unicode__(self): return self.name def comments(self):