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
|
mergeable = True
|
||||||
merge_additive_fields = [
|
|
||||||
'usernames',
|
def __init__(self, request):
|
||||||
'member_uuids',
|
super(PersonView, self).__init__(request)
|
||||||
]
|
|
||||||
merge_fields = merge_additive_fields + [
|
# always get a reference to the People Handler
|
||||||
'uuid',
|
app = self.get_rattail_app()
|
||||||
'first_name',
|
self.handler = app.get_people_handler()
|
||||||
'last_name',
|
|
||||||
'display_name',
|
|
||||||
]
|
|
||||||
|
|
||||||
def configure_grid(self, g):
|
def configure_grid(self, g):
|
||||||
super(PersonView, self).configure_grid(g)
|
super(PersonView, self).configure_grid(g)
|
||||||
|
@ -190,9 +187,7 @@ class PersonView(MasterView):
|
||||||
names[key] = None
|
names[key] = None
|
||||||
|
|
||||||
# do explicit name update w/ common handler logic
|
# do explicit name update w/ common handler logic
|
||||||
app = self.get_rattail_app()
|
self.handler.update_names(person, **names)
|
||||||
handler = app.get_people_handler()
|
|
||||||
handler.update_names(person, **names)
|
|
||||||
|
|
||||||
return person
|
return person
|
||||||
|
|
||||||
|
@ -365,33 +360,30 @@ class PersonView(MasterView):
|
||||||
(model.VendorContact, 'person_uuid'),
|
(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):
|
def get_merge_data(self, person):
|
||||||
return {
|
return self.handler.get_merge_preview_data(person)
|
||||||
'uuid': person.uuid,
|
|
||||||
'first_name': person.first_name,
|
def validate_merge(self, removing, keeping):
|
||||||
'last_name': person.last_name,
|
reason = self.handler.why_not_merge(removing, keeping)
|
||||||
'display_name': person.display_name,
|
if reason:
|
||||||
'usernames': [u.username for u in person.users],
|
raise Exception(reason)
|
||||||
'member_uuids': [m.uuid for m in person.members],
|
|
||||||
}
|
|
||||||
|
|
||||||
def merge_objects(self, removing, keeping):
|
def merge_objects(self, removing, keeping):
|
||||||
"""
|
self.handler.perform_merge(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):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in a new issue