Use "People Handler" to update names, when editing person or user
This commit is contained in:
parent
b3867d9c89
commit
fb7a572519
|
@ -2,7 +2,7 @@
|
||||||
################################################################################
|
################################################################################
|
||||||
#
|
#
|
||||||
# Rattail -- Retail Software Framework
|
# Rattail -- Retail Software Framework
|
||||||
# Copyright © 2010-2020 Lance Edgar
|
# Copyright © 2010-2021 Lance Edgar
|
||||||
#
|
#
|
||||||
# This file is part of Rattail.
|
# This file is part of Rattail.
|
||||||
#
|
#
|
||||||
|
@ -179,6 +179,37 @@ class PeopleView(MasterView):
|
||||||
return True
|
return True
|
||||||
return not self.is_person_protected(person)
|
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):
|
def delete_instance(self, person):
|
||||||
"""
|
"""
|
||||||
Supplements the default logic as follows:
|
Supplements the default logic as follows:
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
################################################################################
|
################################################################################
|
||||||
#
|
#
|
||||||
# Rattail -- Retail Software Framework
|
# Rattail -- Retail Software Framework
|
||||||
# Copyright © 2010-2020 Lance Edgar
|
# Copyright © 2010-2021 Lance Edgar
|
||||||
#
|
#
|
||||||
# This file is part of Rattail.
|
# This file is part of Rattail.
|
||||||
#
|
#
|
||||||
|
@ -268,12 +268,12 @@ class UsersView(PrincipalMasterView):
|
||||||
|
|
||||||
# create/update person as needed
|
# create/update person as needed
|
||||||
names = {}
|
names = {}
|
||||||
if 'first_name_' in form:
|
if 'first_name_' in form and data['first_name_']:
|
||||||
names['first'] = 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_']
|
names['last'] = data['last_name_']
|
||||||
if 'display_name_' in form:
|
if 'display_name_' in form and data['display_name_']:
|
||||||
names['display'] = data['display_name_']
|
names['full'] = data['display_name_']
|
||||||
# we will not have a person reference yet, when creating new user. if
|
# we will not have a person reference yet, when creating new user. if
|
||||||
# that is the case, go ahead and load it, if specified.
|
# that is the case, go ahead and load it, if specified.
|
||||||
if self.creating and user.person_uuid:
|
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()]):
|
if not user.person and any([n for n in names.values()]):
|
||||||
user.person = model.Person()
|
user.person = model.Person()
|
||||||
if user.person:
|
if user.person:
|
||||||
if names.get('first'):
|
app = self.get_rattail_app()
|
||||||
user.person.first_name = names['first']
|
handler = app.get_people_handler()
|
||||||
if names.get('last'):
|
handler.update_names(user.person, **names)
|
||||||
user.person.last_name = names['last']
|
|
||||||
if names.get('display'):
|
|
||||||
user.person.display_name = names['display']
|
|
||||||
|
|
||||||
# force "local only" flag unless global access granted
|
# force "local only" flag unless global access granted
|
||||||
if self.secure_global_objects:
|
if self.secure_global_objects:
|
||||||
|
|
Loading…
Reference in a new issue