Added a new field Person.plain as a fallback for names where plain_name() produces the wrong result. Fixes issue #3020.

- Legacy-Id: 18147
This commit is contained in:
Henrik Levkowetz 2020-07-11 20:22:23 +00:00
parent 1e1f056053
commit c6cdbf8ca8
4 changed files with 13 additions and 6 deletions

View file

@ -214,7 +214,7 @@ class IetfAuthTests(TestCase):
self.register_and_verify(email)
settings.LIST_ACCOUNT_DELAY = saved_delay
def test_profile(self):
def test_ietfauth_profile(self):
EmailFactory(person__user__username='plain')
GroupFactory(acronym='mars')
@ -234,6 +234,7 @@ class IetfAuthTests(TestCase):
base_data = {
"name": "Test Nãme",
"plain": "",
"ascii": "Test Name",
"ascii_short": "T. Name",
"affiliation": "Test Org",
@ -247,7 +248,7 @@ class IetfAuthTests(TestCase):
r = self.client.post(url, faulty_ascii)
self.assertEqual(r.status_code, 200)
q = PyQuery(r.content)
self.assertTrue(len(q("form .has-error")) > 0)
self.assertTrue(len(q("form .has-error")) == 1)
# edit details - blank ASCII
blank_ascii = base_data.copy()
@ -255,13 +256,14 @@ class IetfAuthTests(TestCase):
r = self.client.post(url, blank_ascii)
self.assertEqual(r.status_code, 200)
q = PyQuery(r.content)
self.assertTrue(len(q("form .has-error")) > 0) # we get a warning about reconstructed name
self.assertTrue(len(q("form div.has-error ")) == 1) # we get a warning about reconstructed name
self.assertEqual(q("input[name=ascii]").val(), base_data["ascii"])
# edit details
r = self.client.post(url, base_data)
self.assertEqual(r.status_code, 200)
person = Person.objects.get(user__username=username)
self.assertEqual(person.name, "Test Nãme")
self.assertEqual(person.ascii, "Test Name")
self.assertEqual(Person.objects.filter(alias__name="Test Name", user__username=username).count(), 1)

View file

@ -39,7 +39,8 @@ class Person(models.Model):
time = models.DateTimeField(default=datetime.datetime.now) # When this Person record entered the system
# The normal unicode form of the name. This must be
# set to the same value as the ascii-form if equal.
name = models.CharField("Full Name (Unicode)", max_length=255, db_index=True, help_text="Preferred form of name.")
name = models.CharField("Full Name (Unicode)", max_length=255, db_index=True, help_text="Preferred long form of name.")
plain = models.CharField("Plain Name (Unicode)", max_length=64, default='', blank=True, help_text="Preferred plain form of name, if different from the automatic plain form.")
# The normal ascii-form of the name.
ascii = models.CharField("Full Name (ASCII)", max_length=255, help_text="Name as rendered in ASCII (Latin, unaccented) characters.")
# The short ascii-form of the name. Also in alias table if non-null
@ -66,7 +67,10 @@ class Person(models.Model):
return (first and first[0]+"." or "")+(middle or "")+" "+last+(suffix and " "+suffix or "")
def plain_name(self):
if not hasattr(self, '_cached_plain_name'):
self._cached_plain_name = plain_name(self.name)
if self.plain:
self._cached_plain_name = self.plain
else:
self._cached_plain_name = plain_name(self.name)
return self._cached_plain_name
def ascii_name(self):
if not hasattr(self, '_cached_ascii_name'):

View file

@ -49,7 +49,7 @@ class PersonTests(TestCase):
EmailFactory(person=person, primary=False, active=False)
self.assertTrue(primary.address in person.formatted_email())
def test_profile(self):
def test_person_profile(self):
person = PersonFactory(with_bio=True)
self.assertTrue(person.photo is not None)

View file

@ -155,6 +155,7 @@
{% endfor %}
{% bootstrap_field person_form.name layout="horizontal" %}
{% bootstrap_field person_form.plain layout="horizontal" %}
{% bootstrap_field person_form.ascii layout="horizontal" %}
{% if roles %}
{% bootstrap_field person_form.biography layout="horizontal" %}