Skip to content

Commit

Permalink
The scheme parameter is always empty now
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mhl committed Nov 26, 2015
1 parent 3256803 commit 6b03c21
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 42 deletions.
29 changes: 2 additions & 27 deletions pombola/core/management/commands/core_merge_people.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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(
Expand All @@ -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
Expand Down
8 changes: 2 additions & 6 deletions pombola/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion pombola/south_africa/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
10 changes: 2 additions & 8 deletions pombola/south_africa/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 \
Expand Down

0 comments on commit 6b03c21

Please sign in to comment.