Move "merge 2 people" logic into People Handler
view now delegates to handler, which lives in the rattail package
This commit is contained in:
parent
5836099746
commit
cf32d4235e
|
@ -85,16 +85,13 @@ class PersonView(MasterView):
|
|||
]
|
||||
|
||||
mergeable = True
|
||||
merge_additive_fields = [
|
||||
'usernames',
|
||||
'member_uuids',
|
||||
]
|
||||
merge_fields = merge_additive_fields + [
|
||||
'uuid',
|
||||
'first_name',
|
||||
'last_name',
|
||||
'display_name',
|
||||
]
|
||||
|
||||
def __init__(self, request):
|
||||
super(PersonView, self).__init__(request)
|
||||
|
||||
# always get a reference to the People Handler
|
||||
app = self.get_rattail_app()
|
||||
self.handler = app.get_people_handler()
|
||||
|
||||
def configure_grid(self, g):
|
||||
super(PersonView, self).configure_grid(g)
|
||||
|
@ -190,9 +187,7 @@ class PersonView(MasterView):
|
|||
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)
|
||||
self.handler.update_names(person, **names)
|
||||
|
||||
return person
|
||||
|
||||
|
@ -365,33 +360,30 @@ class PersonView(MasterView):
|
|||
(model.VendorContact, 'person_uuid'),
|
||||
]
|
||||
|
||||
def get_merge_fields(self):
|
||||
fields = self.handler.get_merge_preview_fields()
|
||||
return [field['name'] for field in fields]
|
||||
|
||||
def get_merge_additive_fields(self):
|
||||
fields = self.handler.get_merge_preview_fields()
|
||||
return [field['name'] for field in fields
|
||||
if field.get('additive')]
|
||||
|
||||
def get_merge_coalesce_fields(self):
|
||||
fields = self.handler.get_merge_preview_fields()
|
||||
return [field['name'] for field in fields
|
||||
if field.get('coalesce')]
|
||||
|
||||
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],
|
||||
}
|
||||
return self.handler.get_merge_preview_data(person)
|
||||
|
||||
def validate_merge(self, removing, keeping):
|
||||
reason = self.handler.why_not_merge(removing, keeping)
|
||||
if reason:
|
||||
raise Exception(reason)
|
||||
|
||||
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()
|
||||
self.handler.perform_merge(removing, keeping)
|
||||
|
||||
def view_profile(self):
|
||||
"""
|
||||
|
|
Loading…
Reference in a new issue