Skip to content

Commit f2c31f2

Browse files
committed
Changed the 1id_index generation to use a new Person method .plain_ascii(). Added tests for some Person name methods.
- Legacy-Id: 11993
1 parent 807e89c commit f2c31f2

4 files changed

Lines changed: 37 additions & 4 deletions

File tree

ietf/idindex/index.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ def active_drafts_index_by_group(extra_values=()):
239239
if d:
240240
if "authors" not in d:
241241
d["authors"] = []
242-
d["authors"].append(a.author.person.plain_name())
242+
d["authors"].append(a.author.person.plain_ascii()) # This should probably change to .plain_name() when non-ascii names are permitted
243243

244244
# put docs into groups
245245
for d in docs_dict.itervalues():

ietf/person/factories.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Meta:
3131

3232
user = factory.SubFactory(UserFactory)
3333
name = factory.LazyAttribute(lambda p: '%s %s'%(p.user.first_name,p.user.last_name))
34-
ascii = factory.LazyAttribute(lambda p: unidecode(p.name))
34+
ascii = factory.LazyAttribute(lambda p: unicode(unidecode(p.name).strip()))
3535

3636
class Params:
3737
with_bio = factory.Trait(

ietf/person/models.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from django.template.loader import render_to_string
1313
from django.utils.text import slugify
1414

15+
import debug # pyflakes:ignore
1516

1617
from ietf.person.name import name_parts, initials
1718
from ietf.utils.mail import send_mail_preformatted
@@ -55,10 +56,22 @@ def ascii_name(self):
5556
# It's possibly overkill with unidecode() here, but needed until
5657
# we're validating the content of the ascii field, and have
5758
# verified that the field is ascii clean in the database:
58-
self._cached_ascii_name = unidecode(self.ascii)
59+
if not all(ord(c) < 128 for c in self.ascii):
60+
self._cached_ascii_name = unidecode(self.ascii).strip()
61+
else:
62+
self._cached_ascii_name = self.ascii
5963
else:
60-
self._cached_ascii_name = unidecode(self.plain_name())
64+
self._cached_ascii_name = unidecode(self.plain_name()).strip()
6165
return self._cached_ascii_name
66+
def plain_ascii(self):
67+
if not hasattr(self, '_cached_plain_ascii'):
68+
if self.ascii:
69+
ascii = unidecode(self.ascii).strip()
70+
else:
71+
ascii = unidecode(self.name).strip()
72+
prefix, first, middle, last, suffix = name_parts(ascii)
73+
self._cached_plain_ascii = u" ".join([first, last])
74+
return self._cached_plain_ascii
6275
def initials(self):
6376
return initials(self.ascii or self.name)
6477
def last_name(self):

ietf/person/tests.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# -*- coding: utf-8 -*-
2+
13
import json
24
from pyquery import PyQuery
35

@@ -48,3 +50,21 @@ def test_profile(self):
4850
r = self.client.get(photo_url)
4951
self.assertEqual(r.status_code, 200)
5052

53+
def test_name_methods(self):
54+
person = PersonFactory(name=u"Dr. Jens F. Möller", )
55+
56+
self.assertEqual(person.name, u"Dr. Jens F. Möller" )
57+
self.assertEqual(person.ascii_name(), u"Dr. Jens F. Moller" )
58+
self.assertEqual(person.plain_name(), u"Jens Möller" )
59+
self.assertEqual(person.plain_ascii(), u"Jens Moller" )
60+
self.assertEqual(person.initials(), u"J. F.")
61+
self.assertEqual(person.first_name(), u"Jens" )
62+
self.assertEqual(person.last_name(), u"Möller" )
63+
64+
person = PersonFactory(name=u"吴建平")
65+
# The following are probably incorrect because the given name should
66+
# be Jianping and the surname should be Wu ...
67+
# TODO: Figure out better handling for names with CJK characters.
68+
# Maybe use ietf.person.cjk.*
69+
self.assertEqual(person.ascii_name(), u"Wu Jian Ping")
70+

0 commit comments

Comments
 (0)