From c6cdbf8ca8d703091ff08b41c39bac06b6e83de6 Mon Sep 17 00:00:00 2001 From: Henrik Levkowetz Date: Sat, 11 Jul 2020 20:22:23 +0000 Subject: [PATCH] Added a new field Person.plain as a fallback for names where plain_name() produces the wrong result. Fixes issue #3020. - Legacy-Id: 18147 --- ietf/ietfauth/tests.py | 8 +++++--- ietf/person/models.py | 8 ++++++-- ietf/person/tests.py | 2 +- ietf/templates/registration/edit_profile.html | 1 + 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/ietf/ietfauth/tests.py b/ietf/ietfauth/tests.py index 6aa9c9444..fc8629f2a 100644 --- a/ietf/ietfauth/tests.py +++ b/ietf/ietfauth/tests.py @@ -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) diff --git a/ietf/person/models.py b/ietf/person/models.py index 3d41e7fb7..a22d49978 100644 --- a/ietf/person/models.py +++ b/ietf/person/models.py @@ -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'): diff --git a/ietf/person/tests.py b/ietf/person/tests.py index 61089eee5..684936c2e 100644 --- a/ietf/person/tests.py +++ b/ietf/person/tests.py @@ -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) diff --git a/ietf/templates/registration/edit_profile.html b/ietf/templates/registration/edit_profile.html index 23f63e31e..e4557bdac 100644 --- a/ietf/templates/registration/edit_profile.html +++ b/ietf/templates/registration/edit_profile.html @@ -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" %}