From 24273da2569693304dab431fa6bf538c4bf3189c Mon Sep 17 00:00:00 2001 From: Henrik Levkowetz Date: Sat, 29 Jul 2017 14:02:41 +0000 Subject: [PATCH] Backed out commit 14000; the code is not idempotent and will create duplicate Person objects. - Legacy-Id: 14004 --- ietf/stats/tests.py | 20 ----------------- ietf/stats/utils.py | 53 --------------------------------------------- 2 files changed, 73 deletions(-) diff --git a/ietf/stats/tests.py b/ietf/stats/tests.py index 29f1c8c35..ad30b4ef3 100644 --- a/ietf/stats/tests.py +++ b/ietf/stats/tests.py @@ -1,4 +1,3 @@ - import datetime from mock import patch @@ -6,7 +5,6 @@ from pyquery import PyQuery from requests import Response from django.urls import reverse as urlreverse -from django.contrib.auth.models import User from ietf.utils.test_data import make_test_data, make_review_data from ietf.utils.test_utils import login_testing_unauthorized, TestCase, unicontent @@ -201,21 +199,3 @@ class StatisticsTests(TestCase): get_meeting_registration_data(meeting) query = MeetingRegistration.objects.filter(first_name='John',last_name='Smith',country_code='US') self.assertTrue(query.count(), 1) - self.assertTrue(isinstance(query[0].person,Person)) - - @patch('requests.get') - def test_get_meeting_registration_data_user_exists(self, mock_get): - response = Response() - response.status_code = 200 - response._content = '[{"LastName":"Smith","FirstName":"John","Company":"ABC","Country":"US","Email":"john.doe@example.us"}]' - user = User.objects.create(username="john.doe@example.us") - user.save() - - mock_get.return_value = response - meeting = MeetingFactory(type_id='ietf', date=datetime.date(2016,7,14), number="96") - get_meeting_registration_data(meeting) - query = MeetingRegistration.objects.filter(first_name='John',last_name='Smith',country_code='US') - self.assertTrue(query.count(), 1) - self.assertTrue(isinstance(query[0].person, Person)) - - diff --git a/ietf/stats/utils.py b/ietf/stats/utils.py index 3702a0a3b..d700395d6 100644 --- a/ietf/stats/utils.py +++ b/ietf/stats/utils.py @@ -6,11 +6,6 @@ from django.conf import settings from ietf.stats.models import AffiliationAlias, AffiliationIgnoredEnding, CountryAlias, MeetingRegistration from ietf.name.models import CountryName -from ietf.person.models import Person, Email -from django.contrib.auth.models import User -from unidecode import unidecode - - def compile_affiliation_ending_stripping_regexp(): parts = [] @@ -231,11 +226,7 @@ def get_meeting_registration_data(meeting): else: raise RuntimeError("Could not decode response from registrations API: '%s...'" % (response.content[:64], )) - - # for each user identified in the Registration system - # Create a DataTracker MeetingRegistration object for registration in decoded: - person = None object, created = MeetingRegistration.objects.get_or_create( meeting_id=meeting.pk, first_name=registration['FirstName'], @@ -244,50 +235,6 @@ def get_meeting_registration_data(meeting): country_code=registration['Country'], email=registration['Email'], ) - - # Add a Person object to MeetingRegistration object - # if valid email is available - if not object.person: - # If the person already exists do not try to create a new one - emails = Email.objects.filter(address=registration["Email"]) - # there can only be on Email object with a unique email address (primary key) - if len(emails) == 1: - person = emails[0].person - # Create a new Person object - else: - # ascii_name - convert from unicode if necessary - regname = "%s %s" % (registration["FirstName"], registration["LastName"]) - # if there are any unicode characters decode the string to ascii - ascii_name = unidecode(regname).strip() - - # Create a new user object if it does not exist already - # if the user already exists do not try to create a new one - users = User.objects.filter(username=registration["Email"]) - if len(users) > 0: - user = users[0] - else: - # Create a new user. - user = User.objects.create( - first_name=registration["FirstName"], - last_name=registration["LastName"], - username=registration["Email"], - email=registration["Email"] - ) - user.save() - - # Create the new Person object. - person = Person.objects.create( - name=regname, - ascii=ascii_name, - affiliation=registration["Company"], - user=user - ) - person.save() - - # update the person object to an actual value - object.person = person - object.save() - if created: num_created += 1 num_processed += 1