|
6 | 6 |
|
7 | 7 | from ietf.stats.models import AffiliationAlias, AffiliationIgnoredEnding, CountryAlias, MeetingRegistration |
8 | 8 | 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 | + |
9 | 14 |
|
10 | 15 | def compile_affiliation_ending_stripping_regexp(): |
11 | 16 | parts = [] |
@@ -226,15 +231,65 @@ def get_meeting_registration_data(meeting): |
226 | 231 | else: |
227 | 232 | raise RuntimeError("Could not decode response from registrations API: '%s...'" % (response.content[:64], )) |
228 | 233 |
|
| 234 | + |
| 235 | + # for each user identified in the Registration system |
| 236 | + # Create a DataTracker MeetingRegistration object |
229 | 237 | for registration in decoded: |
230 | | - object, created = MeetingRegistration.objects.get_or_create( |
| 238 | + person = None |
| 239 | + obj, created = MeetingRegistration.objects.get_or_create( |
231 | 240 | meeting_id=meeting.pk, |
232 | 241 | first_name=registration['FirstName'], |
233 | 242 | last_name=registration['LastName'], |
234 | 243 | affiliation=registration['Company'], |
235 | 244 | country_code=registration['Country'], |
236 | 245 | email=registration['Email'], |
237 | 246 | ) |
| 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 | + |
238 | 293 | if created: |
239 | 294 | num_created += 1 |
240 | 295 | num_processed += 1 |
|
0 commit comments