From 90c36ba53bcad3bcf70a515c38b7be2b533981ff Mon Sep 17 00:00:00 2001 From: jnga Date: Sun, 19 Jun 2022 06:58:23 -0400 Subject: [PATCH] D. Key Editor: handle deleting a couplet that is already partially deleted. (see #793) --- gobotany/editor/views.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/gobotany/editor/views.py b/gobotany/editor/views.py index 48762ccd..3f6149cd 100644 --- a/gobotany/editor/views.py +++ b/gobotany/editor/views.py @@ -661,11 +661,13 @@ def dkey(request, slug='key-to-the-families'): elif command == 'delete': # Delete a couplet. leads_to_delete = dkey_models.Lead.objects.filter(parent=lead_id) - # Be careful about deleting lead records: - # verify that there are two, and delete no more than two. - if leads_to_delete.count() == 2: + # Be careful about deleting lead records: delete no more than two. + # (Allow for just one in case the user deleted one elsewhere.) + if leads_to_delete.count() <= 2: + # Keep track of the deleted leads for debugging. deleted_leads.append(leads_to_delete[0].id) - deleted_leads.append(leads_to_delete[1].id) + if leads_to_delete.count() == 2: + deleted_leads.append(leads_to_delete[1].id) leads_to_delete.delete() elif command == 'promote': # Determine the new parent of the leads that will be promoted.