From 6b03c21f527eda595734f23e22840f81d93eb0d2 Mon Sep 17 00:00:00 2001 From: Mark Longair Date: Thu, 26 Nov 2015 14:36:10 +0000 Subject: [PATCH] The scheme parameter is always empty now All invocations (from views) of the pombola_person_to_sayit_speaker method just passed in the empty string as the scheme parameter, so we can assume that's always the case. This also means that we can remove the --sayit-id-scheme option from core_merge_people, and don't need to try to remove and Identifier with that scheme since the Identifier model's scheme field isn't allowed to be blank. --- .../management/commands/core_merge_people.py | 29 ++----------------- pombola/core/views.py | 8 ++--- pombola/south_africa/tests.py | 2 +- pombola/south_africa/views.py | 10 ++----- 4 files changed, 7 insertions(+), 42 deletions(-) diff --git a/pombola/core/management/commands/core_merge_people.py b/pombola/core/management/commands/core_merge_people.py index e080b88943..bb3a308b16 100644 --- a/pombola/core/management/commands/core_merge_people.py +++ b/pombola/core/management/commands/core_merge_people.py @@ -60,8 +60,6 @@ class Command(PersonSpeakerMappingsMixin, BaseCommand): make_option("--delete-person", dest="delete_person", type="string", help="The ID or slug of the person to delete", metavar="PERSON-ID"), - make_option("--sayit-id-scheme", dest="sayit_id_scheme", type="string", - help="The name of the SayIt ID schema (if used)"), make_option('--noinput', dest='interactive', action='store_false', default=True, help="Do NOT prompt the user for input of any kind"), @@ -122,20 +120,13 @@ def handle(self, *args, **options): if not options['quiet']: print "Moving SayIt speeches" - if options['sayit_id_scheme'] is None: - raise CommandError("You must specify --sayit-id-scheme") - from speeches.models import Speech delete_sayit_speaker = self.pombola_person_to_sayit_speaker( - to_delete, - options['sayit_id_scheme'] - ) + to_delete) keep_sayit_speaker = self.pombola_person_to_sayit_speaker( - to_keep, - options['sayit_id_scheme'] - ) + to_keep) if delete_sayit_speaker and keep_sayit_speaker: Speech.objects.filter( @@ -148,22 +139,6 @@ def handle(self, *args, **options): print "One or both of the people does not have a SayIt " \ "speaker. Not moving speeches." - try: - # Delete the identifier from the losing side, as all - # speeches are now the new one - ct = core_models.ContentType.objects.get_for_model( - core_models.Person) - core_models.Identifier.objects.get( - content_type=ct, - object_id=to_delete.id, - scheme=options['sayit_id_scheme'] - ).delete() - except core_models.Identifier.DoesNotExist: - # If there was no such identifier, it's nothing to - # worry about; they're not used for mapping to SayIt - # speakers any more anyway. - pass - # Switch the person or speaker model on all affected # models in core: # core_models.Position diff --git a/pombola/core/views.py b/pombola/core/views.py index 0a45650cf3..19e7d51578 100644 --- a/pombola/core/views.py +++ b/pombola/core/views.py @@ -163,14 +163,10 @@ def get_template_names(self): return ["core/person_%s.html" % self.sub_page] class PersonSpeakerMappingsMixin(object): - def pombola_person_to_sayit_speaker(self, person, scheme): + def pombola_person_to_sayit_speaker(self, person): try: expected_popit_id = 'core_person:{0}'.format(person.id) - speaker = Speaker.objects.get( - person__popit_id=(scheme + expected_popit_id) - ) - return speaker - + return Speaker.objects.get(person__popit_id=expected_popit_id) except ObjectDoesNotExist: return None diff --git a/pombola/south_africa/tests.py b/pombola/south_africa/tests.py index 911c6ab1d0..b44cfa8709 100644 --- a/pombola/south_africa/tests.py +++ b/pombola/south_africa/tests.py @@ -356,7 +356,7 @@ def setUp(self): def test_person_to_speaker_resolution(self): person = models.Person.objects.get(slug='moomin-finn') - speaker = self.pombola_person_to_sayit_speaker(person, '') + speaker = self.pombola_person_to_sayit_speaker(person) self.assertEqual( speaker.name, 'Moomin Finn' ) def test_generation_of_interests_table(self): diff --git a/pombola/south_africa/views.py b/pombola/south_africa/views.py index 6adc666266..047130725d 100644 --- a/pombola/south_africa/views.py +++ b/pombola/south_africa/views.py @@ -493,10 +493,7 @@ class SAPersonDetail(PersonSpeakerMappingsMixin, PersonDetail): def get_recent_speeches_for_section(self, tags, limit=5): pombola_person = self.object - sayit_speaker = self.pombola_person_to_sayit_speaker( - pombola_person, - '' - ) + sayit_speaker = self.pombola_person_to_sayit_speaker(pombola_person) if not sayit_speaker: # Without a speaker we can't find any speeches @@ -1128,10 +1125,7 @@ def get_context_data(self, **kwargs): tag = get_object_or_404(Tag, name=speech_tag) # SayIt speaker is different to core.Person, Load the speaker - speaker = self.pombola_person_to_sayit_speaker( - person, - '' - ) + speaker = self.pombola_person_to_sayit_speaker(person) # Load the speeches. Pagination is done in the template speeches = Speech.objects \