Improve speaker merging code.

This commit is contained in:
Edward Betts 2023-09-25 17:35:21 +01:00
parent 99b180681f
commit a5f8070179

13
main.py
View file

@ -186,9 +186,20 @@ def merge() -> str | Response:
print(other_ids, "->", merge_to_id)
conference_people = model.ConferencePerson.query.filter(
model.ConferencePerson.person_id.in_(other_ids)
)
with database.session.begin():
merge_to = model.Person.query.get(merge_to_id)
existing_conferences = {conf.id for conf in merge_to.conferences}
to_delete = [
cp for cp in conference_people if cp.conference_id in existing_conferences
]
for cp in to_delete:
database.session.delete(cp)
if merge_to_id != name_from_person_id:
merge_to = model.Person.query.get(merge_to_id)
name_from_person = model.Person.query.get(name_from_person_id)
merge_to.name = name_from_person.name