From c8c45e22132bdf086e4da60e0999cffed7f8be7c Mon Sep 17 00:00:00 2001 From: Robert Sparks Date: Thu, 4 Feb 2016 22:50:50 +0000 Subject: [PATCH] Stop making active unknown-email- objects. Mark existing such objects as inactive. Tweak exception handling in submit/utils to make it obvious that the utilities will not change the person an existing Email record is pointing to. Commit ready for merge. - Legacy-Id: 10780 --- .../0005_deactivate_unknown_email.py | 21 +++++++++++++++++++ ietf/submit/utils.py | 11 +++++++--- 2 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 ietf/person/migrations/0005_deactivate_unknown_email.py diff --git a/ietf/person/migrations/0005_deactivate_unknown_email.py b/ietf/person/migrations/0005_deactivate_unknown_email.py new file mode 100644 index 000000000..4ef73a2c1 --- /dev/null +++ b/ietf/person/migrations/0005_deactivate_unknown_email.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations + +def forward(apps, schema_editor): + Email = apps.get_model('person','Email') + Email.objects.filter(address__startswith="unknown-email-",active=True).update(active=False) + +def reverse(apps,schema_editor): + pass + +class Migration(migrations.Migration): + + dependencies = [ + ('person', '0004_auto_20150308_0440'), + ] + + operations = [ + migrations.RunPython(forward,reverse) + ] diff --git a/ietf/submit/utils.py b/ietf/submit/utils.py index 24c0c5f8c..a5052bed9 100644 --- a/ietf/submit/utils.py +++ b/ietf/submit/utils.py @@ -313,21 +313,26 @@ def ensure_person_email_info_exists(name, email): # make sure we have an email address if email: + active = True addr = email.lower() else: # we're in trouble, use a fake one + active = False addr = u"unknown-email-%s" % person.name.replace(" ", "-") try: email = person.email_set.get(address=addr) except Email.DoesNotExist: try: - # maybe it's pointing to someone else - email = Email.objects.get(address=addr) + # An Email object pointing to some other person will not exist + # at this point, because get_person_from_name_email would have + # returned that person, but it's possible that an Email record + # not associated with any Person exists + email = Email.objects.get(address=addr,person__isnull=True) except Email.DoesNotExist: # most likely we just need to create it email = Email(address=addr) - email.active = True + email.active = active email.person = person email.save()