Commit 4e5e9a0f authored by Jérome Perrin's avatar Jérome Perrin Committed by Tristan Cavelier

ERP5: make Person.getTitle fallback consistent with Base

when no title, fallback to reference then id
parent 4b275002
...@@ -96,11 +96,12 @@ class Person(Node, LoginAccountProviderMixin, EncryptedPasswordMixin): ...@@ -96,11 +96,12 @@ class Person(Node, LoginAccountProviderMixin, EncryptedPasswordMixin):
first name, middle name and last name first name, middle name and last name
""" """
if not self.title: if not self.title:
return ' '.join([x for x in (self.getFirstName(), title = ' '.join([x for x in (self.getFirstName(),
self.getMiddleName(), self.getMiddleName(),
self.getLastName()) if x]) self.getLastName()) if x])
else: if title:
return self.title return title
return super(Person, self).getTitle(**kw)
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getTranslatedTitle') 'getTranslatedTitle')
...@@ -110,11 +111,12 @@ class Person(Node, LoginAccountProviderMixin, EncryptedPasswordMixin): ...@@ -110,11 +111,12 @@ class Person(Node, LoginAccountProviderMixin, EncryptedPasswordMixin):
first name, middle name and last name first name, middle name and last name
""" """
if not self.title: if not self.title:
return ' '.join([x for x in (self.getTranslatedFirstName(**kw), title = ' '.join([x for x in (self.getTranslatedFirstName(**kw),
self.getTranslatedMiddleName(**kw), self.getTranslatedMiddleName(**kw),
self.getTranslatedLastName(**kw)) if x]) self.getTranslatedLastName(**kw)) if x])
else: if title:
return self.title return title
return super(Person, self).getTranslatedTitle(**kw)
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'title_or_id') 'title_or_id')
...@@ -124,7 +126,10 @@ class Person(Node, LoginAccountProviderMixin, EncryptedPasswordMixin): ...@@ -124,7 +126,10 @@ class Person(Node, LoginAccountProviderMixin, EncryptedPasswordMixin):
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'hasTitle') 'hasTitle')
def hasTitle(self): def hasTitle(self):
return not not self.getTitle() return self.hasFirstName() or \
self.hasLastName() or \
self.hasMiddleName() or \
self._baseHasTitle()
def _setReference(self, value): def _setReference(self, value):
""" """
......
...@@ -90,9 +90,37 @@ class TestPerson(ERP5TypeTestCase): ...@@ -90,9 +90,37 @@ class TestPerson(ERP5TypeTestCase):
self.assertEqual(person_copy_obj.getReference(), person.getReference()) self.assertEqual(person_copy_obj.getReference(), person.getReference())
# title & first_name, last_name # title & first_name, last_name
def testEmptyTitle(self): def testEmptyTitleFallbackOnId(self):
p = self._makeOne() p = self._makeOne(id=self.id())
self.assertEqual('', p.getTitle()) self.assertEqual(self.id(), p.getTitle())
def testEmptyTranslatedTitleFallbackOnId(self):
p = self._makeOne(id=self.id())
self.assertEqual(self.id(), p.getTranslatedTitle())
def testEmptyCompactTitleFallbackOnId(self):
p = self._makeOne(id=self.id())
self.assertEqual(self.id(), p.getCompactTitle())
def testEmptyCompactTranslatedTitleFallbackOnId(self):
p = self._makeOne(id=self.id())
self.assertEqual(self.id(), p.getCompactTranslatedTitle())
def testEmptyTitleFallbackOnReference(self):
p = self._makeOne(reference='reference')
self.assertEqual('reference', p.getTitle())
def testEmptyTranslatedTitleFallbackOnReference(self):
p = self._makeOne(reference='reference')
self.assertEqual('reference', p.getTranslatedTitle())
def testEmptyCompactTitleFallbackOnReference(self):
p = self._makeOne(reference='reference')
self.assertEqual('reference', p.getCompactTitle())
def testEmptyCompactTranslatedTitleFallbackOnReference(self):
p = self._makeOne(reference='reference')
self.assertEqual('reference', p.getCompactTranslatedTitle())
def testSetFirstName(self): def testSetFirstName(self):
p = self._makeOne() p = self._makeOne()
...@@ -112,6 +140,22 @@ class TestPerson(ERP5TypeTestCase): ...@@ -112,6 +140,22 @@ class TestPerson(ERP5TypeTestCase):
p.setMiddleName('middle') p.setMiddleName('middle')
self.assertEqual('first middle last', p.getTitle()) self.assertEqual('first middle last', p.getTitle())
def testTranslatedTitleFromFirstLastName(self):
p = self._makeOne(id='person')
p.setFirstName('first')
p.setLastName('last')
self.assertEqual('first last', p.getTranslatedTitle())
p.setMiddleName('middle')
self.assertEqual('first middle last', p.getTranslatedTitle())
def testCompactTranslatedTitleFromFirstLastName(self):
p = self._makeOne(id='person')
p.setFirstName('first')
p.setLastName('last')
self.assertEqual('first last', p.getCompactTranslatedTitle())
p.setMiddleName('middle')
self.assertEqual('first middle last', p.getCompactTranslatedTitle())
def testEditFirstNameLastName(self): def testEditFirstNameLastName(self):
# using 'edit' method # using 'edit' method
p = self._makeOne(id='person') p = self._makeOne(id='person')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment