Add very basic support for merging 2 People

this is not very complete, but was enough for what i needed at the moment.
almost seems like incomplete feature may be worse than none at all?  but then
again some sort of default starting point is nice i guess...
This commit is contained in:
Lance Edgar 2020-12-07 11:40:26 -06:00
parent ac5139b7c4
commit 42eb72422d

View file

@ -98,6 +98,18 @@ class PeopleView(MasterView):
'users', 'users',
] ]
mergeable = True
merge_additive_fields = [
'usernames',
'member_uuids',
]
merge_fields = merge_additive_fields + [
'uuid',
'first_name',
'last_name',
'display_name',
]
def configure_grid(self, g): def configure_grid(self, g):
super(PeopleView, self).configure_grid(g) super(PeopleView, self).configure_grid(g)
@ -337,6 +349,34 @@ class PeopleView(MasterView):
(model.VendorContact, 'person_uuid'), (model.VendorContact, 'person_uuid'),
] ]
def get_merge_data(self, person):
return {
'uuid': person.uuid,
'first_name': person.first_name,
'last_name': person.last_name,
'display_name': person.display_name,
'usernames': [u.username for u in person.users],
'member_uuids': [m.uuid for m in person.members],
}
def merge_objects(self, removing, keeping):
"""
Execute a merge operation on the two given person records.
"""
# move Member records to final Person
for member in list(removing.members):
removing.members.remove(member)
keeping.members.append(member)
# move User records to final Person
for user in list(removing.users):
removing.users.remove(user)
keeping.users.append(user)
# delete unwanted Person
self.Session.delete(removing)
self.Session.flush()
def view_profile(self): def view_profile(self):
""" """
View which exposes the "full profile" for a given person, i.e. all View which exposes the "full profile" for a given person, i.e. all