Changed the 1id_index generation to use a new Person method .plain_ascii(). Added tests for some Person name methods.
- Legacy-Id: 11993
This commit is contained in:
parent
807e89cb85
commit
f2c31f242b
|
@ -239,7 +239,7 @@ def active_drafts_index_by_group(extra_values=()):
|
|||
if d:
|
||||
if "authors" not in d:
|
||||
d["authors"] = []
|
||||
d["authors"].append(a.author.person.plain_name())
|
||||
d["authors"].append(a.author.person.plain_ascii()) # This should probably change to .plain_name() when non-ascii names are permitted
|
||||
|
||||
# put docs into groups
|
||||
for d in docs_dict.itervalues():
|
||||
|
|
|
@ -31,7 +31,7 @@ class PersonFactory(factory.DjangoModelFactory):
|
|||
|
||||
user = factory.SubFactory(UserFactory)
|
||||
name = factory.LazyAttribute(lambda p: '%s %s'%(p.user.first_name,p.user.last_name))
|
||||
ascii = factory.LazyAttribute(lambda p: unidecode(p.name))
|
||||
ascii = factory.LazyAttribute(lambda p: unicode(unidecode(p.name).strip()))
|
||||
|
||||
class Params:
|
||||
with_bio = factory.Trait(
|
||||
|
|
|
@ -12,6 +12,7 @@ from django.contrib.auth.models import User
|
|||
from django.template.loader import render_to_string
|
||||
from django.utils.text import slugify
|
||||
|
||||
import debug # pyflakes:ignore
|
||||
|
||||
from ietf.person.name import name_parts, initials
|
||||
from ietf.utils.mail import send_mail_preformatted
|
||||
|
@ -55,10 +56,22 @@ class PersonInfo(models.Model):
|
|||
# It's possibly overkill with unidecode() here, but needed until
|
||||
# we're validating the content of the ascii field, and have
|
||||
# verified that the field is ascii clean in the database:
|
||||
self._cached_ascii_name = unidecode(self.ascii)
|
||||
if not all(ord(c) < 128 for c in self.ascii):
|
||||
self._cached_ascii_name = unidecode(self.ascii).strip()
|
||||
else:
|
||||
self._cached_ascii_name = unidecode(self.plain_name())
|
||||
self._cached_ascii_name = self.ascii
|
||||
else:
|
||||
self._cached_ascii_name = unidecode(self.plain_name()).strip()
|
||||
return self._cached_ascii_name
|
||||
def plain_ascii(self):
|
||||
if not hasattr(self, '_cached_plain_ascii'):
|
||||
if self.ascii:
|
||||
ascii = unidecode(self.ascii).strip()
|
||||
else:
|
||||
ascii = unidecode(self.name).strip()
|
||||
prefix, first, middle, last, suffix = name_parts(ascii)
|
||||
self._cached_plain_ascii = u" ".join([first, last])
|
||||
return self._cached_plain_ascii
|
||||
def initials(self):
|
||||
return initials(self.ascii or self.name)
|
||||
def last_name(self):
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import json
|
||||
from pyquery import PyQuery
|
||||
|
||||
|
@ -48,3 +50,21 @@ class PersonTests(TestCase):
|
|||
r = self.client.get(photo_url)
|
||||
self.assertEqual(r.status_code, 200)
|
||||
|
||||
def test_name_methods(self):
|
||||
person = PersonFactory(name=u"Dr. Jens F. Möller", )
|
||||
|
||||
self.assertEqual(person.name, u"Dr. Jens F. Möller" )
|
||||
self.assertEqual(person.ascii_name(), u"Dr. Jens F. Moller" )
|
||||
self.assertEqual(person.plain_name(), u"Jens Möller" )
|
||||
self.assertEqual(person.plain_ascii(), u"Jens Moller" )
|
||||
self.assertEqual(person.initials(), u"J. F.")
|
||||
self.assertEqual(person.first_name(), u"Jens" )
|
||||
self.assertEqual(person.last_name(), u"Möller" )
|
||||
|
||||
person = PersonFactory(name=u"吴建平")
|
||||
# The following are probably incorrect because the given name should
|
||||
# be Jianping and the surname should be Wu ...
|
||||
# TODO: Figure out better handling for names with CJK characters.
|
||||
# Maybe use ietf.person.cjk.*
|
||||
self.assertEqual(person.ascii_name(), u"Wu Jian Ping")
|
||||
|
||||
|
|
Loading…
Reference in a new issue