Strip whitespace from registration data during import. Includes migration for existing data. Fixes #2356. Commit ready for merge.
- Legacy-Id: 14088
This commit is contained in:
parent
f2668cf61d
commit
044b89169a
38
ietf/stats/migrations/0005_fix_registration_data.py
Normal file
38
ietf/stats/migrations/0005_fix_registration_data.py
Normal file
|
@ -0,0 +1,38 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.10.7 on 2017-08-29 12:00
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations
|
||||
from django.db.models import Q
|
||||
|
||||
def strip_spaces(apps, schema_editor):
|
||||
MeetingRegistration = apps.get_model("stats", "MeetingRegistration")
|
||||
for reg in MeetingRegistration.objects.filter(Q(first_name__startswith=' ') |
|
||||
Q(first_name__endswith=' ')).distinct():
|
||||
reg.first_name = reg.first_name.strip()
|
||||
reg.save()
|
||||
|
||||
for reg in MeetingRegistration.objects.filter(Q(last_name__startswith=' ') |
|
||||
Q(last_name__endswith=' ')).distinct():
|
||||
reg.last_name = reg.last_name.strip()
|
||||
reg.save()
|
||||
|
||||
for reg in MeetingRegistration.objects.filter(Q(affiliation__startswith=' ') |
|
||||
Q(affiliation__endswith=' ')).distinct():
|
||||
reg.affiliation = reg.affiliation.strip()
|
||||
reg.save()
|
||||
|
||||
for reg in MeetingRegistration.objects.filter(Q(email__startswith=' ') |
|
||||
Q(email__endswith=' ')).distinct():
|
||||
reg.email = reg.email.strip()
|
||||
reg.save()
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('stats', '0004_meetingregistration_email'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(strip_spaces, migrations.RunPython.noop),
|
||||
]
|
|
@ -191,9 +191,10 @@ class StatisticsTests(TestCase):
|
|||
|
||||
@patch('requests.get')
|
||||
def test_get_meeting_registration_data(self, mock_get):
|
||||
'''Test function to get reg data. Confirm leading/trailing spaces stripped'''
|
||||
response = Response()
|
||||
response.status_code = 200
|
||||
response._content = '[{"LastName":"Smith","FirstName":"John","Company":"ABC","Country":"US","Email":"john.doe@example.us"}]'
|
||||
response._content = '[{"LastName":"Smith ","FirstName":" John","Company":"ABC","Country":"US","Email":"john.doe@example.us"}]'
|
||||
mock_get.return_value = response
|
||||
meeting = MeetingFactory(type_id='ietf', date=datetime.date(2016,7,14), number="96")
|
||||
get_meeting_registration_data(meeting)
|
||||
|
|
|
@ -229,11 +229,11 @@ def get_meeting_registration_data(meeting):
|
|||
for registration in decoded:
|
||||
object, created = MeetingRegistration.objects.get_or_create(
|
||||
meeting_id=meeting.pk,
|
||||
first_name=registration['FirstName'],
|
||||
last_name=registration['LastName'],
|
||||
affiliation=registration['Company'],
|
||||
country_code=registration['Country'],
|
||||
email=registration['Email'],
|
||||
first_name=registration['FirstName'].strip(),
|
||||
last_name=registration['LastName'].strip(),
|
||||
affiliation=registration['Company'].strip(),
|
||||
country_code=registration['Country'].strip(),
|
||||
email=registration['Email'].strip(),
|
||||
)
|
||||
if created:
|
||||
num_created += 1
|
||||
|
|
Loading…
Reference in a new issue