Skip to content

Commit bffc711

Browse files
author
Seth Birkholz
committed
Added Person object to ietf/stats/utils.py in get_meeting_registration_data
- Legacy-Id: 13949
1 parent 0c520b0 commit bffc711

1 file changed

Lines changed: 56 additions & 1 deletion

File tree

ietf/stats/utils.py

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66

77
from ietf.stats.models import AffiliationAlias, AffiliationIgnoredEnding, CountryAlias, MeetingRegistration
88
from ietf.name.models import CountryName
9+
from ietf.person.models import Person
10+
from django.contrib.auth.models import User
11+
from unidecode import unidecode
12+
13+
914

1015
def compile_affiliation_ending_stripping_regexp():
1116
parts = []
@@ -226,15 +231,65 @@ def get_meeting_registration_data(meeting):
226231
else:
227232
raise RuntimeError("Could not decode response from registrations API: '%s...'" % (response.content[:64], ))
228233

234+
235+
# for each user identified in the Registration system
236+
# Create a DataTracker MeetingRegistration object
229237
for registration in decoded:
230-
object, created = MeetingRegistration.objects.get_or_create(
238+
person = None
239+
obj, created = MeetingRegistration.objects.get_or_create(
231240
meeting_id=meeting.pk,
232241
first_name=registration['FirstName'],
233242
last_name=registration['LastName'],
234243
affiliation=registration['Company'],
235244
country_code=registration['Country'],
236245
email=registration['Email'],
237246
)
247+
248+
# Add a Person object to MeetingRegistration object
249+
# if valid email is available
250+
if not obj.person and "Email" in registration and '@' in registration["Email"]:\
251+
# If the person already exists do not try to create a new one
252+
persons = Person.objects.filter(user__username=registration["Email"])
253+
if len(persons) > 0:
254+
person = persons[0]
255+
# Create a new Person object
256+
else:
257+
# ascii_name - convert from unicode if necessary
258+
regname = "%s %s" % (registration["FirstName"], registration["LastName"])
259+
# if there are any unicode characters decode the string to ascii
260+
if not all(ord(c) < 128 for c in regname):
261+
ascii_name = unidecode(regname).strip()
262+
# it is already ascii, no need to convert
263+
else:
264+
ascii_name = regname
265+
266+
# Create a new user object if it does not exist already
267+
# if the user already exists do not try ot create a new one
268+
users = User.objects.filter(username=registration["Email"])
269+
if len(users) > 0:
270+
user = users[0]
271+
else:
272+
# Create a new user.
273+
user = User.objects.create(
274+
first_name=registration["FirstName"],
275+
last_name=registration["LastName"],
276+
username=registration["Email"],
277+
email=registration["Email"]
278+
)
279+
280+
# Create the new Person object.
281+
person = Person.objects.create(
282+
name=registration["Email"],
283+
ascii=ascii_name,
284+
affiliation=registration["Company"],
285+
user=user
286+
)
287+
person.save()
288+
289+
# update the person object to an actual value
290+
obj.person = person
291+
obj.save()
292+
238293
if created:
239294
num_created += 1
240295
num_processed += 1

0 commit comments

Comments
 (0)