Skip to content

Commit

Permalink
fixup! Remove inactive person links
Browse files Browse the repository at this point in the history
  • Loading branch information
VirginiaDooley committed Jun 12, 2024
1 parent 5c3a25b commit edfe8a9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
7 changes: 7 additions & 0 deletions ynr/apps/candidatebot/helpers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import contextlib
import re

import pypandoc
Expand Down Expand Up @@ -196,3 +197,9 @@ def add_theyworkforyou_id(self, twfy_id):
value = f"https://www.theyworkforyou.com/mp/{twfy_id}/"
internal_id = f"uk.org.publicwhip/person/{twfy_id}"
self.edit_field("theyworkforyou", value, internal_id=internal_id)

def remove_person_identifier(self, identifier):
with contextlib.suppress(PersonIdentifier.DoesNotExist):
identifier.delete()
self.person.invalidate_identifier_cache()
return self.person
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from urllib.parse import urlparse

import requests
from candidatebot.helpers import CandidateBot
from django.core.management.base import BaseCommand
from people.models import Person
from popolo.models import Membership
Expand Down Expand Up @@ -66,9 +67,9 @@ def handle(self, *args, **options):
]
)
# delete the identifier from the person identifiers
bot = CandidateBot(person.pk, ignore_errors=True)
identifier.person.get_all_identifiers.remove(identifier)
identifier.delete()
identifier.person.save()
bot.remove_person_identifier(identifier)
print(
f"Deleted {identifier.value_type}:{identifier.value} from {person.name}"
f"Candidatebot deleted {identifier.value_type}:{identifier.value} from {person.name}"
)
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def test_remove_inactive_person_identifiers(self):
self.person.get_all_identifiers[1].value,
"http://www.conservatives.com/about/our-team/example.com",
)
call_command("remove_inactive_person_links")
call_command("candidatebot_remove_inactive_person_links")
self.person.refresh_from_db()
self.assertEqual(len(self.person.get_all_identifiers), 1)
self.assertEqual(
Expand Down

0 comments on commit edfe8a9

Please sign in to comment.