From 5acff0e95f10956fb5d8ec3df1496c38ae85b38b Mon Sep 17 00:00:00 2001 From: Henrik Levkowetz Date: Fri, 1 Jul 2016 20:08:28 +0000 Subject: [PATCH] Added a method Person.ascii_name() for use when generating 1id-*.txt files. Added caching for Person.plain_name(). Fixes a problem with non-ascii names in 1id-*.txt which lead to non-ascii names in xml2rfc reference files. - Legacy-Id: 11510 --- ietf/idindex/index.py | 2 +- ietf/person/models.py | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/ietf/idindex/index.py b/ietf/idindex/index.py index e0cda9adc..eacf71ffa 100644 --- a/ietf/idindex/index.py +++ b/ietf/idindex/index.py @@ -239,7 +239,7 @@ def active_drafts_index_by_group(extra_values=()): if d: if "authors" not in d: d["authors"] = [] - d["authors"].append(unicode(a.author.person)) + d["authors"].append(a.author.person.ascii_name()) # put docs into groups for d in docs_dict.itervalues(): diff --git a/ietf/person/models.py b/ietf/person/models.py index 06daf2278..f420650d9 100644 --- a/ietf/person/models.py +++ b/ietf/person/models.py @@ -1,8 +1,9 @@ # Copyright The IETF Trust 2007, All Rights Reserved import datetime -from urlparse import urljoin from hashids import Hashids +from unidecode import unidecode +from urlparse import urljoin from django.conf import settings @@ -44,8 +45,20 @@ class PersonInfo(models.Model): prefix, first, middle, last, suffix = self.ascii_parts() return (first and first[0]+"." or "")+(middle or "")+" "+last+(suffix and " "+suffix or "") def plain_name(self): - prefix, first, middle, last, suffix = name_parts(self.name) - return u" ".join([first, last]) + if not hasattr(self, '_cached_plain_name'): + prefix, first, middle, last, suffix = name_parts(self.name) + self._cached_plain_name = u" ".join([first, last]) + return self._cached_plain_name + def ascii_name(self): + if not hasattr(self, '_cached_ascii_name'): + if self.ascii: + # 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) + else: + self._cached_ascii_name = unidecode(self.plain_name()) + return self._cached_ascii_name def initials(self): return initials(self.ascii or self.name) def last_name(self):