Ignore:
Timestamp:
27 Feb 2017, 06:50:46 (8 years ago)
Author:
Henrik Bettermann
Message:

Hide firstname, middlename or surname if the character length is less than two.

Location:
main/waeup.aaue/trunk/src/waeup/aaue/utils
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.aaue/trunk/src/waeup/aaue/utils/tests.py

    r8444 r14594  
    1818from waeup.kofa.testing import FunctionalTestCase
    1919from waeup.aaue.testing import FunctionalLayer
     20from waeup.aaue.utils.utils import CustomKofaUtils
    2021
    2122
     
    2425    layer = FunctionalLayer
    2526
    26     def test_foo(self):
    27         '''Test method foo.
    28         '''
    29         return
     27    def test_fullname(self):
     28        util = CustomKofaUtils()
     29        firstname = 'John'
     30        middlename = 'Z'
     31        lastname = 'Streep'
     32        self.assertEqual(
     33            util.fullname(firstname, lastname, middlename), 'STREEP, John')
     34        firstname = 'J'
     35        self.assertEqual(
     36            util.fullname(firstname, lastname, middlename), 'STREEP')
     37        lastname = None
     38        self.assertEqual(
     39            util.fullname(firstname, lastname, middlename), '')
     40        firstname = 'John'
     41        self.assertEqual(
     42            util.fullname(firstname, lastname, middlename), 'John')
     43        firstname = 'J'
     44        middlename = 'Babatunde'
     45        lastname = 'Iron'
     46        self.assertEqual(
     47            util.fullname(firstname, lastname, middlename), 'IRON, Babatunde')
  • main/waeup.aaue/trunk/src/waeup/aaue/utils/utils.py

    r14571 r14594  
    215215        except AttributeError:
    216216            pass
    217         # We do not necessarily have the middlename attribute
    218         if middlename:
     217        # We remove single initial
     218        if firstname and len(firstname) == 1:
     219            firstname = ''
     220        if middlename and len(middlename) == 1:
     221            middlename = ''
     222        if lastname and len(lastname) == 1:
     223            lastname = ''
     224        # We construct givennames
     225        givennames = ''
     226        if middlename and firstname:
    219227            givennames = '%s %s' % (firstname, middlename)
    220         else:
    221             givennames = '%s' % firstname
     228        elif firstname:
     229            givennames = firstname
     230        elif middlename:
     231            givennames = middlename
    222232        givennames = string.capwords(
    223233            givennames.replace('-', ' - ')).replace(' - ', '-')
    224         fullname = '%s, %s' % (lastname, givennames)
     234        # We construct fullname
     235        fullname = ''
     236        if lastname and givennames:
     237            fullname = '%s, %s' % (lastname, givennames)
     238        elif lastname:
     239            fullname = lastname
     240        elif givennames:
     241            fullname = givennames
    225242        if '<' in fullname:
    226243            return 'XXX'
Note: See TracChangeset for help on using the changeset viewer.