Use "People Handler" to update names, when editing person or user

This commit is contained in:
Lance Edgar 2021-01-28 14:34:18 -06:00
parent b3867d9c89
commit fb7a572519
2 changed files with 40 additions and 12 deletions

View file

@ -2,7 +2,7 @@
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2020 Lance Edgar
# Copyright © 2010-2021 Lance Edgar
#
# This file is part of Rattail.
#
@ -179,6 +179,37 @@ class PeopleView(MasterView):
return True
return not self.is_person_protected(person)
def objectify(self, form, data=None):
if data is None:
data = form.validated
# do normal create/update
person = super(PeopleView, self).objectify(form, data)
# collect data from all name fields
names = {}
if 'first_name' in form:
names['first'] = data['first_name']
if 'middle_name' in form:
names['middle'] = data['middle_name']
if 'last_name' in form:
names['last'] = data['last_name']
if 'display_name' in form:
names['full'] = data['display_name']
# TODO: why do we find colander.null values in data at this point?
# ugh, for now we must convert them
for key in names:
if names[key] is colander.null:
names[key] = None
# do explicit name update w/ common handler logic
app = self.get_rattail_app()
handler = app.get_people_handler()
handler.update_names(person, **names)
return person
def delete_instance(self, person):
"""
Supplements the default logic as follows:

View file

@ -2,7 +2,7 @@
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2020 Lance Edgar
# Copyright © 2010-2021 Lance Edgar
#
# This file is part of Rattail.
#
@ -268,12 +268,12 @@ class UsersView(PrincipalMasterView):
# create/update person as needed
names = {}
if 'first_name_' in form:
if 'first_name_' in form and data['first_name_']:
names['first'] = data['first_name_']
if 'last_name_' in form:
if 'last_name_' in form and data['last_name_']:
names['last'] = data['last_name_']
if 'display_name_' in form:
names['display'] = data['display_name_']
if 'display_name_' in form and data['display_name_']:
names['full'] = data['display_name_']
# we will not have a person reference yet, when creating new user. if
# that is the case, go ahead and load it, if specified.
if self.creating and user.person_uuid:
@ -283,12 +283,9 @@ class UsersView(PrincipalMasterView):
if not user.person and any([n for n in names.values()]):
user.person = model.Person()
if user.person:
if names.get('first'):
user.person.first_name = names['first']
if names.get('last'):
user.person.last_name = names['last']
if names.get('display'):
user.person.display_name = names['display']
app = self.get_rattail_app()
handler = app.get_people_handler()
handler.update_names(user.person, **names)
# force "local only" flag unless global access granted
if self.secure_global_objects: