Changeset - 987fb3c68c47
[Not reviewed]
0 2 0
Lance Edgar (lance) - 2 months ago 2024-08-15 19:39:46
lance@edbob.org
fix: improve logic/fallback for `str(person)`
2 files changed with 10 insertions and 3 deletions:
0 comments (0 inline, 0 general)
rattail/db/model/people.py
Show inline comments
 
@@ -95,7 +95,11 @@ class Person(ContactMixin, Base):
 
    modified = sa.Column(sa.DateTime(), nullable=True, onupdate=datetime.datetime.utcnow)
 

	
 
    def __str__(self):
 
        return self.display_name or ""
 
        if self.display_name:
 
            return self.display_name
 
        if self.first_name or self.last_name:
 
            return f"{self.first_name} {self.last_name}".strip()
 
        return "(NO NAME!)"
 

	
 
    @property
 
    def user(self):
tests/db/model/test_people.py
Show inline comments
 
@@ -13,13 +13,16 @@ else:
 

	
 
    class TestPerson(DataTestCase):
 

	
 
        def test_unicode(self):
 
        def test_str(self):
 
            person = model.Person()
 
            self.assertEqual(str(person), "")
 
            self.assertEqual(str(person), "(NO NAME!)")
 

	
 
            person = model.Person(display_name="Fred Flintstone")
 
            self.assertEqual(str(person), "Fred Flintstone")
 

	
 
            person = model.Person(first_name="Barney", last_name="Rubble")
 
            self.assertEqual(str(person), "Barney Rubble")
 

	
 
        # TODO: this is duplicated in TestPerson
 
        def test_add_email_address(self):
 
            person = model.Person()
0 comments (0 inline, 0 general)