def createPartyFromName(apps, name):
TransactionParty = apps.get_model('<STR_LIT>', '<STR_LIT>')<EOL>StaffMember = apps.get_model('<STR_LIT>', '<STR_LIT>')<EOL>User = apps.get_model('<STR_LIT>', '<STR_LIT>')<EOL>firstName = name.split('<STR_LIT:U+0020>')[<NUM_LIT:0>]<EOL>lastName = '<STR_LIT:U+0020>'.join(name.split('<STR_LIT:U+0020>')[<NUM_LIT:1>:])<EOL>members = StaffMember.objects.filter(<EOL>firstName__istartswith=firstName, lastName__istartswith=lastName<EOL>)<EOL>users = User.objects.filter(<EOL>first_name__istartswith=firstName, last_name__istartswith=lastName<EOL>)<EOL>if members.count() == <NUM_LIT:1>:<EOL><INDENT>this_member = members.first()<EOL>party = TransactionParty.objects.get_or_create(<EOL>staffMember=this_member,<EOL>defaults={<EOL>'<STR_LIT:name>': getFullName(this_member),<EOL>'<STR_LIT:user>': this_member.userAccount,<EOL>}<EOL>)[<NUM_LIT:0>]<EOL><DEDENT>elif users.count() == <NUM_LIT:1>:<EOL><INDENT>this_user = users.first()<EOL>party = TransactionParty.objects.get_or_create(<EOL>user=this_user,<EOL>defaults={<EOL>'<STR_LIT:name>': getFullName(this_user),<EOL>'<STR_LIT>': getattr(this_user, '<STR_LIT>', None),<EOL>}<EOL>)[<NUM_LIT:0>]<EOL><DEDENT>else:<EOL><INDENT>party = TransactionParty.objects.get_or_create(<EOL>name=name<EOL>)[<NUM_LIT:0>]<EOL><DEDENT>return party<EOL>
For creating/matching TransactionParty objects using names alone.
Look for staff members with the same name and match to them first if there is
exactly one match.  Then, look for users and match them if there is exactly one
match. Otherwise, just generate a TransactionParty for the name only.