Merge lp:~mhall119/loco-team-portal/meeting-unicode-error into lp:loco-team-portal

Proposed by Michael Hall
Status: Merged
Approved by: Chris Johnston
Approved revision: 441
Merged at revision: 444
Proposed branch: lp:~mhall119/loco-team-portal/meeting-unicode-error
Merge into: lp:loco-team-portal
Diff against target: 51 lines (+17/-17)
2 files modified
loco_directory/meetings/models.py (+2/-2)
loco_directory/meetings/tests.py (+15/-15)
To merge this branch: bzr merge lp:~mhall119/loco-team-portal/meeting-unicode-error
Reviewer Review Type Date Requested Status
Chris Johnston Approve
Review via email: mp+65810@code.launchpad.net

Commit message

Make sure that AgendaItem.__unicode__ returns a unicode string, rather than an ascii string.

Description of the change

Overview
========
If an agenda item's title contains unicode, it throws an exception when trying to convert the AgendaItem instance to a string.

Details
=======
This happens when calling unicode() on an AgendaItem, because it's __unicode__ method is actually returning an ascii string, not a unicode string. Make sure that AgendaItem.__unicode__ returns a unicode string, rather than an ascii string.

To post a comment you must log in.
Revision history for this message
Chris Johnston (cjohnston) wrote :

:-)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'loco_directory/meetings/models.py'
2--- loco_directory/meetings/models.py 2011-06-21 00:00:35 +0000
3+++ loco_directory/meetings/models.py 2011-06-24 16:26:36 +0000
4@@ -189,7 +189,7 @@
5
6 def __unicode__(self):
7 if self.parent is None:
8- return '%s' % self.title
9+ return u'%s' % self.title
10 else:
11- return '%s->%s' % (self.parent, self.title)
12+ return u'%s->%s' % (self.parent, self.title)
13
14
15=== modified file 'loco_directory/meetings/tests.py'
16--- loco_directory/meetings/tests.py 2010-12-02 07:34:58 +0000
17+++ loco_directory/meetings/tests.py 2011-06-24 16:26:36 +0000
18@@ -6,18 +6,18 @@
19 """
20
21 from django.test import TestCase
22-
23-class SimpleTest(TestCase):
24- def test_basic_addition(self):
25- """
26- Tests that 1 + 1 always equals 2.
27- """
28- self.failUnlessEqual(1 + 1, 2)
29-
30-__test__ = {"doctest": """
31-Another way to test that 1 + 1 is equal to 2.
32-
33->>> 1 + 1 == 2
34-True
35-"""}
36-
37+from meetings.models import AgendaItem
38+
39+
40+class UnicodeTest(TestCase):
41+
42+ def setUp(self):
43+ super(UnicodeTest, self).setUp()
44+ self.test_string = 'test \xc3 string'
45+
46+ def test_unicode_agenda_title(self):
47+ item = AgendaItem(title=self.test_string)
48+ self.assertEquals(unicode(item), self.test_string)
49+
50+ child = AgendaItem(title=self.test_string, parent=item)
51+ self.assertEquals(unicode(child), u'%s->%s' % (self.test_string, self.test_string))

Subscribers

People subscribed via source and target branches